Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql-server

'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'.

like image 720
user133466 Avatar asked Mar 12 '11 16:03

user133466


People also ask

How do I connect to SQL Server using Windows Authentication?

Open SQL Server Management Studio. In Connect to Server, select Database Engine, enter your SQL Server name, and enter administrator credentials to connect to the server. Select Connect. In Object Explorer, expand the SQL Server, expand Security, right-click Logins, and then select New Login.


2 Answers

Try using Windows authentication:

Data Source=localhost\SQLEXPRESS;Initial Catalog=test;Integrated Security=SSPI;
like image 116
Andomar Avatar answered Oct 03 '22 07:10

Andomar


Try like this:

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

Also make sure you have enabled SQL authentication.

like image 41
Darin Dimitrov Avatar answered Oct 03 '22 09:10

Darin Dimitrov