Hello,
I have been stuck on this problem for a couple of days.
The sys admin gave my username access to a database on sql server 2005 using windows authentication. I try to connect to it using this and it says that my username cannot access the db. What can be wrong, the sys admin said that all looks well on his side.
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString =
"Data Source=serverName;Initial Catalog=DBName;User Id=MyUsername;Password=myPassword;";
myConnection.Open();
Thank you, Karina

Cannot Connect to SQL Server 2005
hmayer
Karina, what credentials is the ASP.NET running under If no authentication was configured, is might be running under the internet anonyomus account, <machine-name>\IUSR_<machine-name>. In this case, you can have the database administrator give access and appropriate permissions to this account to login and access the application database, depending on what kind of access is required.
Security is a topic I can't cover appropriately in a forum post, but I would recommend taking a look at the security guidance index at http://msdn.microsoft.com/practices/Topics/security/default.aspx pull=/library/en-us/dnpag2/html/SecurityGuidanceIndex.asp.
Marcelo - MSFT
MarcNelson
llebron
Hello:
Thank you for the quick reply.
I did what you sugested and change my connection string to:
SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = "Data Source=serverName;Initial Catalog=dbName;Integrated Security=SSPI;";myConnection.Open();
lblInfo.Text =
"server version: " + myConnection.ServerVersion;lblInfo.Text +=
"<br/><b>Connection is:</b>:" + myConnection.State.ToString();myConnection.Close();
I am using VS 2005 (asp.net, c#, 2.0) and a remote Sql server 2005 (NOT express).
This is the error I get:
Server Error in 'myApplication' Application.
Declan_
Well its not using Windows Authentication (also known as trusted connection) so you are using SQL Authentication instead I believe.
what error do you get exactly Have you also tried, just in case, to add:
trusted_connection=false;
at the end of your connection string
which version of SQL 2005 are you using Express
Srdjan
All you need for integrated security is:
Data Source=serverName;Initial Catalog=DBName;Integrated Security=SSPI;";
Try this and let us know if it works. You should never enter your user id and password (domain userid and password) into a connection string. The userid and password in a connection string is only for SQL Server logins not domain logins.