0
I wrote a simple test application in C# (4.5) which does nothing more than connect to a database and display a message. (Basically just to test the deployment and DB connection.) On my local workstation everything works fine. I installed SQL Express 2012, connect as the current user (integrated security), no problems.
However, when deployed to Windows Server 2008, the application can't connect to the database. It keeps getting a login failed error.
On the server I followed the same installation for SQL Express 2012. I'm logged in as Administrator when I run the console application. I even tried turning on mixed mode authentication, creating a user, and connecting as that user. I can connect in SQL Management Studio, but the application always gets a login failed error.
Is there some hidden security setting in Windows Server 2008 which I need to modify to allow a .NET application to connect to a SQL server? What might cause this behavior where I can login to the database via SSMS but not via an application?
Error:
System.Data.SqlClient.SqlException (0x80131904): Cannot open database "TestDatabase" requested by the login. The login failed. Login failed for user 'sa'.
Naturally, this is the version of the error when I tried connecting as sa
as sort of a last ditch effort for testing. The same error happens for TestUser
(a SQL user I created for this) as well as PERSONALSERVER\Administrator
(the current logged in user running the application).
The connection strings I've tried are:
Data Source=localhost\sqlexpress2012;Initial Catalog=TestDatabase;Integrated Security=True
Data Source=localhost\sqlexpress2012;Initial Catalog=TestDatabase;User Id=TestUser;Password=testpassword
have you got it working? – user46193 – 2014-12-04T11:10:19.863
Do you use windows authentication in both SSMS and your app? – Amiram Korach – 2012-11-12T14:31:11.263
@AmiramKorach: I've tried Windows auth and SQL auth in both, same results. – David – 2012-11-12T14:33:34.097
Maybe your connection string is wrong. Please add it. – Amiram Korach – 2012-11-12T14:35:17.867
Question updated with additional details. – David – 2012-11-12T14:41:31.187
1Can you check the Sql Server's log? I would not have expected a 'login failed' message unless you are actually talking to the sql database. – sgmoore – 2012-11-12T15:10:00.243
1
ockquote>
Is there some hidden security setting in Windows Server 2008 which I need to modify to allow a .NET application to connect to a SQL server? Easy way to disprove this is downloading and trying LinqPad (from http://www.linqpad.net/)