Answered by:
SQL Connection String

Question
-
Hey all,
I am having an issue with a Connection String. Here is the string:
myConnection = new SqlConnection("Initial Catalog=myDB;Data Source=IPofServer;User ID=LocalUserwithDBOaccess;Password=pw;");
However, I can not get the connection to go through. When I look at the logs it says:
2011-02-22 09:42:00.53 Logon Error: 18456, Severity: 14, State: 38.
2011-02-22 09:42:00.53 Logon Login failed for user 'Domain\UserName'. Reason: Failed to open the explicitly specified database. [CLIENT: IP]The domain account that it is listing is my account which also has DBO access to the database. The two funny things is, my account has access and it is not even trying to use the SQL account that I set up in the string. What would cause this issue or do I have something wrong with my connection string?
Thanks,
Matt
Answers
-
okay, so i should have forgotted to read something important here, I just noted that this is in your webservice? Remember IIS handles security in a different way:
Few things to note here:
For ASP.NET 2.0 applications, you should store connection strings in the <connectionStrings> section of your application's Web.config file. The connection string used with Windows authentication must include either the Trusted_Connection=Yes attribute, or the equivalent attribute Integrated Security=SSPI, as shown here.
<connectionStrings> <add name="MyDbConn1" connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes;"/> <add name="MyDbConn2" connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"/> </connectionStrings>
Next there are two primary things:
-
Using the Network Service Account
-
Using a Custom Service Account
Refer: http://msdn.microsoft.com/en-us/library/ff647396.aspx
Balaji Baskar
http://codesupport.wordpress.com
Click on "Vote As Helpful" and "Mark As Answer" if this has helped you.- Proposed as answer by Balaji Baskar Wednesday, February 23, 2011 2:59 PM
- Marked as answer by Matt11380 Wednesday, February 23, 2011 3:19 PM
-
All replies
-
-
-
-
Try to chang the order to:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
This has got to work... if your server is running and all data (ip, database name, userName nad pw) are correct this must work.
Be careful when you name the database - it has to be only the name, without any dot and ending word (so only "DATABASE NAME").
-
-
myConnection = new SqlConnection("Initial Catalog=myDB;Data Source=IPofServer;User ID=LocalUserwithDBOaccess;Password=pw;");
2011-02-22 09:42:00.53 Logon Error: 18456, Severity: 14, State: 38.
2011-02-22 09:42:00.53 Logon Login failed for user 'Domain\UserName'. Reason: Failed to open the explicitly specified database. [CLIENT: IP]The domain account that it is listing is my account which also has DBO access to the database. The two funny things is, my account has access and it is not even trying to use the SQL account that I set up in the string. What would cause this issue or do I have something wrong with my connection string?
From looking at the error message's perspective, It is sure that your connection string is CORRECT, the second thing to check is whether the specified userid is the database's user, in other words the specified user id may be associated with the different database and you are trying to open a different database, please check this.
Balaji Baskar
http://codesupport.wordpress.com
Click on "Vote As Helpful" and "Mark As Answer" if this has helped you. -
Thank you for all of the responses. I will answer them in order.
Changing the order for the connection string made no difference.
No external access.
That user is only associated with one database and it is set up as DBO.
I bet this is something very simple, I just can't figure it out.
-
okay, so i should have forgotted to read something important here, I just noted that this is in your webservice? Remember IIS handles security in a different way:
Few things to note here:
For ASP.NET 2.0 applications, you should store connection strings in the <connectionStrings> section of your application's Web.config file. The connection string used with Windows authentication must include either the Trusted_Connection=Yes attribute, or the equivalent attribute Integrated Security=SSPI, as shown here.
<connectionStrings> <add name="MyDbConn1" connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes;"/> <add name="MyDbConn2" connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"/> </connectionStrings>
Next there are two primary things:
-
Using the Network Service Account
-
Using a Custom Service Account
Refer: http://msdn.microsoft.com/en-us/library/ff647396.aspx
Balaji Baskar
http://codesupport.wordpress.com
Click on "Vote As Helpful" and "Mark As Answer" if this has helped you.- Proposed as answer by Balaji Baskar Wednesday, February 23, 2011 2:59 PM
- Marked as answer by Matt11380 Wednesday, February 23, 2011 3:19 PM
-
-