Cant connect application with connection string .\\Sqlexpress

北城以北 提交于 2019-12-23 04:52:12

问题


i am a beginner and using mircosoft Sql Server 2005. i connect with Server name : USER-PC on Windows Authentication. now this is creating a serious problem in my Windows Application. i want to use .\SQLEXPRESS in the connection string in my application but doing this creates an error saying:

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

m trying a lot to solve the problem but cant find the solution. the connection string i used is:

SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS; Initial Catalog=demo; Integrated Security=true");

please provide solution or link to my problem.


回答1:


.\SQLEXPRESS means that you have local instance of SQL Express named as localhost\SQLEXPRESS. If you are trying to access database on server USER-PC then use that like Data Source=USER-PC or if you have a named instance of SQLEXPRESS then use Data Source=USER-PC\\SQLExpress




回答2:


You aren't declaring the name of the database. For example, if your database was called "database1"

@"Data Source=|DataDirectory|\database1.sdf"

Please note this is for a local database in SqlCe 3.5 your database may be serviced based.



来源:https://stackoverflow.com/questions/24270579/cant-connect-application-with-connection-string-sqlexpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!