SQL Server 2012 classic asp connection string - sql-server

I have a SQL Server 2012 Express installation with a new DB called BRD that I have created. I have also created a test table (tempDemo), and a test stored procedure (getStList) in the BRD database. The stored procedure works when I run it in the query window so I believe the table and stored procedure are legit. The SQL Server is set to "SQL Server and Windows Authentication mode".
I then attempted to create a Classic ASP page that then connected to the SQL Server using the following connection string:
objConn.ConnectionString="Provider=SQLOLEDB;Server=XPSI7\SQLEXPRESS;Database=BRD;Integrated Security=SSPI;"
This fails with the following message:
"Microsoft OLE DB Provider for SQL Server error '80004005'
Cannot open database "BRD" requested by the login. The login failed."
When I change the database to MASTER instead of BRD the ASP page does not error out. I'm just testing the connection string by opening it and then closing it, but it appears to work.
I've looked at the security settings for MASTER and BRD in the Object Explorer, but have failed to notice a difference. I've also looked at the IIS_IUSRS for the folders, but no difference either - not sure if this is necessary anyway.

SQL Server authenticates your login at the server level. Then it tries to open the database you've asked to connect to. At this point, you need to either map a database-level user to the server-level login, or use a server-level login that inherently has sufficient privileges to use the database.
A simple (but not secure) way to demonstrate this using SQL Server Authentication:
USE master;
GO
CREATE LOGIN foo
WITH PASSWORD = 'bar', CHECK_POLICY = OFF;
GO
USE BRD;
GO
CREATE USER foo FROM LOGIN foo;
GO
EXEC sp_addrolemember N'db_owner', N'foo';
GO
Now in your ASP connection string, use:
objConn.ConnectionString = "Provider=SQLNCLI;Data Source=XPSI7\SQLEXPRESS;Initial Catalog=BRD;User ID=foo;Password=bar;"
You can also map whatever login you're using to a database user simply doing:
USE BRD;
GO
CREATE USER [YourDomain\IIS_IUSRwhatever]
FROM LOGIN [YourDomain\IIS_IUSRwhatever];
GO
That will grant them access to the database, but it will be up to you to decide what permissions to grant. This assumes that you are allowing anonymous access to the web server; if IIS is challenging and accepting Windows authentication, you'll need to do the above for the user(s) that will be submitting their credentials. In either case you should be able to continue using the connection string you have now.

Try the following connection string:
strConnection = "Provider=SQLNCLI10;Server=server_name;Database=" & BD_REMOTE_INITIAL_CATALOG & ";Uid=" & BD_REMOTE_USER_ID & "; Pwd=*****;"

Related

Using SqlPackage to Extract DB results in "Login failed for user "someUser""

I am new to using SqlPackage.
I have a powershell command that looks something like
.\SqlPackage.exe /TargetFile:"C:\\Program Files\\Microsoft SQL Server\\150\\DAC\bin\\somefile.bacpac" /Action:extract /SourceServerName:"someServer" /SourceDatabaseName:"someDB" /SourceUser:"someUser" /SourcePassword:"somePassword" /DiagnosticsFile:"C:\\Program Files\\Microsoft SQL Server\\150\\DAC\\bin\\extract-log"
When I run this command I get the error
*** Error extracting database:Could not connect to database server.
Login failed for user "someUser"
I have checked the username and password and they are both correct. I used them to successfully login to SSMS. The user is the admistrator on the server, so should not be an issue with permissions I don't think.
I have followed the instructions to view the logs but under the server I do not have a Management tab. I do not understand why since I am the admin on the server.
Does anyone have any ideas on how I can find the source of the issue?
The reason for this error could be one of many. Without the true authentication error, from the SQL Server logs, it's impossible to state what the solution is, but here are a few possible reasons:
The Connection details are incorrect.
You are using the wrong LOGIN and/or password combination. Check that the creditials are correct against those stored in your password management software.
You are connecting to the wrong instance, and the LOGIN does not exist on the instance. Check that the instance details in your connection string are correct.
The LOGIN you are using is disabled. You need to log onto the server and re-enable it:
ALTER LOGIN someUser ENABLE;
The LOGIN doesn't have the connect permission. YOu need to log onto the server and GRANT it:
GRANT CONNECT SQL TO SomeUser
The LOGIN is trying to connect to a database it does not have a mapped USER on. You will need to CREATE the USER objects in the database(s) it requires access to, along with granting those USERs the needed permissions. You would create the USER with:
USE YourDatabase;
GO
CREATE USER SomeUser FOR LOGIN SomeUser;
There is a server trigger causing an error. Check that there are no triggers that are misbehaving that would cause the authentication to fail.
Another reason that would be exposed in the SQL Server log.

What setting has to be done to connect with database with this connection string given below?

In my .exe setup having connection string
Data Source=SERVER;Initial Catalog=POS_Chimur;User ID=sa;Integrated security=false
I have to install database for this exe what settings will be needed according to above connectionString.
Till now I have installed sql server with default instance with name of pc SERVER. Still i am unable to connect with above connection string.
You need to cheat your way in. Here's how I would approach this problem:
Data Source=SERVER;
You can create an alias to point to your final instance using "SQL Server Configuration Manager", "Aliases"
Initial Catalog=POS_Chimur;
You need to have a database named POS_Chimur
User ID=sa;Integrated security=false
Here, you need to provide a SQL login named sa with no password. I recommend to rename actual sa account to original_sa then create a new account named sa with no password. You also need to create a user mapping for that new account in the POS_Chimur database using this code.
CREATE USER sa FOR LOGIN sa;
ALTER ROLE [db_owner] ADD MEMBER sa;
If DBO doesn't work then you can give it SysAdmin rights if you still have error.
If you are using SQL Server security, you need to specify a username and a password, like this (where you replace 'mySApassword' with the actual password):
Server=SERVER;Database=POS_Chimur;User Id=sa;Password=mySApassword;
In the event you want to use Windows security, you will need this connection string:
Server=SERVER;Database=POS_Chimur;Trusted_Connection=True;
If you are running the executable on the same machine as where SQL Server is running, you can replace 'SERVER' with '.' in order to make it work on all computers, if you need to distribute it to more than one pc.
Here's some more information about SQL Server 2008 connection strings.
I see two things mainly:
You are connecting with SQL Server login
Go to SQL Server Management studio
Connect to the database server with administrative account you know and that works
right mouse click on the server in the 'Object Explorer' window
choose security
In the Server authentication group, choose 'SQL Server and Windows Authentication mode'
Restart SQL Server
This account is sa and doesn't have a password
Go to SQL Server Management studio
connect to the database server with administrative account you know and that works
unfold the server object [-]
unfold the Security folder [-]
unfold the Logins folder => find sa login
right click on it and click Properties
In General section uncheck the Enforce password policy checkbox and clean the passwords in both text boxes
In Status section, make sure that Login is Enabled and that the Permissions to connect is set to Grant
click Ok
confirm, that you want to create a login with blank password (which is obviously always a risk)
After performing those steps, please log out, and try to log in again, but change the Authentication drop down value to 'SQL Server Authentication' and try to login with sa and empty password, if it works, then the connection string should be fine too.
You need to mention the Provider. Your connectionstring should look like this.
Data Source=SERVER;Initial Catalog=POS_Chimur;User ID=sa;Integrated security=false; Provider="System.Data.SqlClient"

Bad T-SQL code for account creation

How do I create a User using SQL code to join an SQL Server via SQL Server authentication mode. I used the code
CREATE LOGIN ANNACASSAR
WITH PASSWORD = '';
GO
CREATE USER ANNACASSAR FOR LOGIN ANNACASSAR;
GO
But I get this error:
Cannot connect to moscow\SQLSERVERMSWDEV.
Additional information:
login failed for user ANNACASSAR
(Microsoft SQL Server error 18456)
Set your server to Mixed authentication mode (right-click on the server in SSMS, Properties, Security, SQL Server and Windows Authentication mode, then restart the server).
However, you really should set a password, because it's a real security risk to create a login without a password.

SQL Server 2008 - Login failed for user 'user1' The user is not associated with a trusted SQL Server connection

I have installed SQL Server 2008 R2 on Windows XP.
In installation process I selected 'SQL Server and Windows Authentication Mode'
When I click right button of the mouse in SQL Server Management Studio on Server -> Security tab 'SQL server and Windows Authentication Mode' is selected.
But when I click on my Database -> Properties - View connection properties Authentication Method is set on Windows Authentication.
To my database was added one user1 with password user1.
But I can't log in to my database from C# (Visual Studio 2008) because error occurs:
Login failed for user 'user1' The
user is not associated with a trusted
SQL Server connection
What isn't right ?
When I get:
string connectionStr = #"Data Source=rmzcmp\SQLExpress;Initial Catalog=ResourcesTmp;Integrated Security=True";
I have following error:
{"Cannot open database \"ResourcesTmp\" requested by the login. The login failed.\r\nLogin failed for user 'RMZCMP\rm'."}
rm is my original user name on which I log in to my computer.
When I get rm I have error:
{"Login failed for user 'rm'. The user is not associated with a trusted SQL Server connection."}
again.
Regards
You say a user was created in your database - did you also create a login to your server?
In SQL Server 2005 and up, security is a two-step process:
you first must define a login that enables a user to even log in to that SQL Server
based on that login, you can define user in your individual databases
Also: you're not showing us your connection string, so we can only guess what settings you're using. From the error message, I'm almost guessing you're using Integrated Security in your connection string - but from your other points in the question, it seems you've created a specific user (and possibly a login for that user) - so you don't want to use integrated (Windows) security...
Most likely, your connection string is invalid - or you're missing a login - or both. You need to give us a bit more information for us to be able to really help!
Can you change your Connection string based on :
Connection string.com
Make sure that your installation of SQL Server is successful.
Ex:
If you can create a SQL Server authentication login
You can login using username/password in SQL Server authentication. Use a connection string like:
Data Source=Servername;Initial Catalog=DatabaseName;User ID=user;Password=sa
But
If you can login using only windows authentication there is something wrong in your installation. Use connection string:
Data Source=Servername;Initial Catalog=DatabaseName;Integrated Security=True
Regards!
That error suggests your application is set to log in with "trusted" (i.e. Windows) credentials and that the Windows account that the program is running as doesn't have a login on the server. Based on the way that you phrased the adding of a user, my guess is that it's a SQL login and you should change your connection string to reflect that.
I created user on my machine (where ms sql is installed)
User name is user1 and password too.
I can log on to Ms sql server on this user (user1)
My connection string is:
string connectionStr = #"Data Source = rmzcmp\SQLExpress; Initial Catalog = ResourcesTmp; User Id = user1; Password = user1;";
I user MS SQL Server 2008
rmzcmp is my computer name.
In ResourcesTmp (my database) ->Security ->Users I have: dbo, guest, INFORMATION_SCHEMA, sys, user1, user2
I don't have sa user.
User1 has following permissions:
Schemas owned by this user:
db_accessadmin
db_datareader
db_datawriter
Database role membership
db_accessadmin
db_datareader
db_datawriter
db_owner
Server properties -> Permissions ->Explicit tab:
Connect SQL : Grantor sa, Grant true.
User1 all checkboxes has false
Security tab -> Server authentication : SQL Serve and Windows Authentication mode is selected as I mentioned in earlier post
Regards
This problem occurs if the user tries to log in with credentials that cannot be validated. This problem can occur in the following scenarios:
Scenario 1: The login may be a SQL Server login but the server only accepts Windows Authentication.
Scenario 2: You are trying to connect by using SQL Server Authentication but the login used does not exist on SQL Server.
Scenario 3: The login may use Windows Authentication but the login is an unrecognized Windows principal. An unrecognized Windows principal means that Windows can't verify the login. This might be because the Windows login is from an untrusted domain.
To resolve this problem, follow the steps that apply to your scenario.
Scenario 1: Configure SQL Server in Mixed Authentication Mode.
SQL Server 2012, SQL Server 2008, and SQL Server 2005
Open SQL Server Management Studio. To do this, click Start, click All Programs, click Microsoft SQL Server 200x (where x is the version of SQL), and then click SQL Server Management Studio.
Right-click the server, and then click Properties. See image.
On the Security page, under Server authentication, click the SQL Server and Windows Authentication mode option button, and then click OK. See image.
In the SQL Server Management Studio dialog box, click OK to restart SQL Server.
see http://support.microsoft.com/kb/555332

Sql Server 2005 login failed

I'm getting message login failed user not associated with a trusted Sql Server Connection
It's a Sql Server 2005 legacy system with linked servers. Whoever set it up left sa password blank (I will be changing.)
How do make a trusted Sql Server connection ?
A "trusted SQL Server connection" error usually means that you're attempting to authenticate using Windows Integrated security and the currently logged on Windows user has not been defined either directly or through group membership to have access to the sql server database being requested.
If the sa password is indeed blank you can login using sql server security as sa + [blank] and associate your Windows account with the appropriate server permissions (and change that sa pwd just after you verify your new account works ok...)
From code a Windows Integrated connection string looks like this:
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
a SQL Server user id/pwd connection string looks like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
(for more varieties check out connectionstrings.com)
Good luck!

Resources