无法连接到 Visual Studio 中的 SQL 服务器
Cannot connect to SQL Server in Visual Studio
我安装了 SQL 服务器和 Visual Studio 并尝试做我的大学项目。
我可以在 Management Studio 中连接到 SQL 服务器,但在 Visual Studio 中无法连接!
- 已启用远程连接
- 所有服务都是运行
- 一切正常,但我不知道为什么会出现此错误:
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 the ...
这段代码有什么问题?
SqlConnection sqcon = new SqlConnection("Data Source=.;Initial Catalog=Badan_Sazi;Integrated Security=True");
SqlCommand com = new SqlCommand();
com.Connection = sqcon;
com.CommandText = "SELECT tbl_morabi.family as 'lname' FROM tbl_morabi";
com.Connection.Open();
我也试过.
、localhost
、my pc name
...同样的错误
- 视觉工作室 2012
- SQL 服务器 Express 2012
SQL服务器Express默认为SQLEXPRESS
实例名
因此请尝试使用 .\SQLEXPRESS
或 (local)\SQLEXPRESS
作为您的服务器+实例名称。
如果这不起作用:您在 Management Studio 中使用什么 服务器名称 连接到您的 SQL 服务器实例??使用那个名字!
您可以检查您的connectionString。应该是下面这样的。
<connectionStrings>
<add name="SampleConnectionString" connectionString="Data Source=machinename\instancename;Initial Catalog=AdventureWorks;Integrated Security=SSPI;Min Pool Size=5;Max Pool Size=60;Connect Timeout=30″ providerName="System.Data.SqlClient"/>
</connectionStrings>
我安装了 SQL 服务器和 Visual Studio 并尝试做我的大学项目。
我可以在 Management Studio 中连接到 SQL 服务器,但在 Visual Studio 中无法连接!
- 已启用远程连接
- 所有服务都是运行
- 一切正常,但我不知道为什么会出现此错误:
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 the ...
这段代码有什么问题?
SqlConnection sqcon = new SqlConnection("Data Source=.;Initial Catalog=Badan_Sazi;Integrated Security=True");
SqlCommand com = new SqlCommand();
com.Connection = sqcon;
com.CommandText = "SELECT tbl_morabi.family as 'lname' FROM tbl_morabi";
com.Connection.Open();
我也试过.
、localhost
、my pc name
...同样的错误
- 视觉工作室 2012
- SQL 服务器 Express 2012
SQL服务器Express默认为SQLEXPRESS
实例名
因此请尝试使用 .\SQLEXPRESS
或 (local)\SQLEXPRESS
作为您的服务器+实例名称。
如果这不起作用:您在 Management Studio 中使用什么 服务器名称 连接到您的 SQL 服务器实例??使用那个名字!
您可以检查您的connectionString。应该是下面这样的。
<connectionStrings>
<add name="SampleConnectionString" connectionString="Data Source=machinename\instancename;Initial Catalog=AdventureWorks;Integrated Security=SSPI;Min Pool Size=5;Max Pool Size=60;Connect Timeout=30″ providerName="System.Data.SqlClient"/>
</connectionStrings>