What is the sql connection string I need to use to access localhost\SQLEXPRESS with Windows Authentication or SQL Authentication?

've installed SQL Express on my PC hoping to do some practice creating tables and then modifying them. I coded a webpage in Visual Studio to, basically, SELECT * from a table in the SQLEXPRESS, but I can never get the connection string to work. Please help

My connection string

"Data Source=localhost\SQLEXPRESS;Initial Catalog=test;User Id=xaa9-PC\xaa9;Password=abcd;"

Error Message:

Query is select * from tblCustomers where username='johndoe' error is Login failed for user 'x309-PC\x309'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Query is select * from tblCustomers where username='johndoe' error is Login failed for user 'x309-PC\x309'.


Solution 1:

Try using Windows authentication:

Data Source=localhost\SQLEXPRESS;Initial Catalog=test;Integrated Security=SSPI;

Solution 2:

Try like this:

string connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=test;User Id=x309;Password=abcd;";

Also make sure you have enabled SQL authentication.