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?
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