Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

Unable to open the SQL Server database

$
0
0

I downloaded SQL Server 2016 Express and Visual Studio 2015.

I get this message when I try to open SQL Server is my Visual Studio program.

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)

My code is

// _ConnectionString = "Server = ARKY/SQLExpress; Database = Tracker; User Id = Track;Password =Track;Trusted_Connection=True;"; _ConnectionString = "Server = ARKY/SQLExpress; Database = Tracker;Trusted_Connection=True;Connect Timeout=10"; SqlConnection myConnection = new SqlConnection(_ConnectionString); try { myConnection.Open(); return ""; } catch (Exception e) { return e.Message + " " + _ConnectionString; }

I tried my different connection strings. This is one example.

ARKY is the name of my computer and SQLEXPRESS is my named instance.


Unable to open the SQL Server database

See the screen shot of my SQL Server database. I will appreciate any suggestions.

Try this:

_ConnectionString = @"Data Source=ARKY\SQLExpress;InitialCatalog=Tracker;Trusted_Connection=True;Connection Timeout=10";

You need a backslash rather than a front slash in your server name, and several parameters are misnamed.

In general, you can open "Server Explorer" in VS, add a data connection to your server there, then click on the data connection and look for the connection string in the properties window. You can cut and paste from there.


Viewing all articles
Browse latest Browse all 3160

Trending Articles