简体   繁体   中英

SQL Server connection string causing error?

In a Winforms application, I have a connection string that causes an error

data source=(local);initial catalog=RegisterDB;persist security info=False

Error:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Thanks for the help Arif Ansari but it still gives the same error.

I'm using Microsoft Visual Studio 2013 Express with SQL Server. I created the database from within Microsoft Visual Studio 2013 Express

Can anyone help?

Hi marc_s

Sorry it didnt work. I created the Database RegisterDB manually with Microsoft Visual Studio 2013 Express in server "(localdb)\\v11.0"

Can anyone help ???????

请尝试一下

 SqlConnection con = new SqlConnection("Data Source=(local);Database=RegisterDB;Integrated Security= true");

try this query as your connection string format

Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;

or this

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

basically check the instance of the server that you are running.

Check if the instance service is running or not. Type services.msc in the start menu to open the Services List. Check for the name SQL SERVER (your instance name) . If the instance status is Started , issue is in your connection string or user permissions. Else if the status is empty or stopped, start the instance and then try connecting.

you may also refer this site for connection string format.

The SQL Server that comes with Visual Studio 2013 is the 2012 Express version - and that by default install the "LocalDB" support.

So I would try this connection string instead:

"data source=(localdb)\v11.0;initial catalog=RegisterDB;Integrated Security=SSPI;"

Does that work? If not: are you auto-creating the database, or if not, did you manually create that database RegisterDB that you're referencing in the connection string?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM