Reputation: 131
I am trying to connect to sql server from wcf service. Using integrated security, it works fine but when I use an account, it fails. I am able to connect to sqL server management studio using this account. I am not sure what I am missing, do I need another provider to do the access. appreciate any feedback.
<add name="GISDBConnectionString" connectionString="Data Source=SVRName;Initial Catalog=db;User ID=GLOBAL\Test;Password=temp"
providerName="System.Data.SqlClient" />
Upvotes: 0
Views: 2042
Reputation: 22456
Based upon the backslash in your account name, I suspect that you are trying to use a windows account in the connection string. There are two kinds of logins that can connect to an SQL Server:
In a connection string, you can opt to use Windows Authentication (Integrated Security=SSPI
, you can also use true
instead of SSPI
). This means that the application will use the account that the process is running under to connect to the SQL Server. The big advantage of this authentication method is that you do not have to store credentials in the connection string. On the other hand, the only way to change the account that is used is to have the application run under another account (or impersonate in the application each time you connect to SQL Server). So there is no way to set another Windows account in the connection string.
If you want to use a SQL Server authenticated account, you have to add the credentials in the connection string (User Id=MyUserName;Password=MyPassword
). You can only use an account that has been created at and granted access to the SQL Server instance you try to connect to. By default, a SQL Server instance is configured to only allow Windows authentication, so you might need to enable SQL Authentication first.
Please note that SQL Server authenticated logins cannot contain a backslash - that's the reason for my assumption that you want to use the credentials of a Windows account in the connection string as the username contains a backslash.
So how can you solve the issue:
Data Source=SVRName;Initial Catalog=db;Integrated Security=SSPI
.Data Source=SVRName;Initial Catalog=db;User ID=SQLAuthLogin;Password=SQLAuthPwd
.Upvotes: 1
Reputation: 21
Try adding Integrated Security=false to your connection string:
<add name="GISDBConnectionString" connectionString="Data Source=SVRName;Initial Catalog=db;Integrated Security=False;User ID=GLOBAL\Test;Password=temp"
providerName="System.Data.SqlClient" />
Upvotes: 0