Hi I'm trying to connect to SQL Server 2008 Express using the following code.
The Connection string was given in the app.config
<connectionStrings>
<add name="sqlConnectionString"
connectionString="DATA SOURCE=.;DATABASE=ExcelPOC;INTEGRATED SECURITY=SSPI;"/>
</connectionStrings>
And the code to connect is as follows.
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConnectionString"].ConnectionString);
conn.Open();
Result is
Login failed for user 'MyPC\Useraccount'
Exception is thrown at conn.Open()
As Darin commented - the error you got is pretty self explanatory. Your connection string specifies SSPI value for integrated security meaning that, as long as username and password are not provided in the connections string the identity of the process running the code will be used to access the database which is what happens in your case and the running user has no login set in the database server.
Either create the necessary login, run the process under a user with an existing login or provide username and password in the connection string.