c# - 错误连接到远程 SQL Server Express 2012 windows 10 c#
问题描述
我在 Windows 10 64 位上安装了 SQL Server Express 2012,来自同一台计算机的连接工作正常,当我从同一网络上的另一台计算机连接时出现问题,我收到错误消息:
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 connection
-provider TCP provider error 0 the wait operation timeout
我尝试了以下事情,但没有解决问题:
- 启用并自动启动 SQL Browser
- 启用 TCP/IP 并为所有 IP 类型设置端口 1433
- 启动命名为 inslance SQLExpress2012 autmaticaly as Build-in : 网络服务
- 使用 IntegratedSecurity=true 无需用户名和密码即可连接
- 数据库正在使用混合模式身份验证
- 在防火墙中为端口 1433 添加例外
- 启用命名管道
- 允许远程连接
这是我的代码:
public static bool TestSQLServerConnection(
string ComputerNameOrIPAddress,
string SQLServerInstanceName,
string PortNumber)
{
try
{
SqlConnectionStringBuilder SQLServerConnectionString = new SqlConnectionStringBuilder();
SQLServerConnectionString.DataSource = ComputerNameOrIPAddress+",+"+PortNumber+"\\"+SQLServerInstanceName;
SQLServerConnectionString.InitialCatalog = DatabseName;
SQLServerConnectionString.TrustServerCertificate = true;
SQLServerConnectionString.IntegratedSecurity = true;
//SQLServerConnectionString.UserID = "...";
//SQLServerConnectionString.NetworkLibrary = "DBMSSOCN";
//SQLServerConnectionString.Password = "...";
SqlConnection con = new SqlConnection(SQLServerConnectionString.ConnectionString);
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText= "select 1";
con.Open();
cmd.ExecuteScalar();
con.Close();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
当我ping它连接的SQL Server的计算机的IP地址或计算机名称并返回响应时,表示计算机已连接到网络。我在没有任何解决方案的情况下搜索,请帮助我。谢谢
解决方案
我在防火墙上添加了 SQL 浏览器服务 UDP 端口 1434 并且工作正常。 使用 SQL Server Management Studio 远程连接到托管在 Azure 虚拟机上的 SQL Server Express 实例
推荐阅读
- wildfly - lsof 增加wildfly 10中的每个请求
- html - 在 div 中将 Icon 和 span 垂直居中
- c# - 剑道网格:未捕获的参考错误:未定义单位
- javascript - 如何在 cytoscape.js 中自定义边缘,以便线条是虚线和动画/闪烁?
- spotify - 以编程方式将 Spotify Connect 设备载入我的帐户
- jquery - Mdbootstrap 的输入选择问题
- ios - 如何在 swift 中为 Post 请求创建 JSON Body
- c# - 将 ComboBox 数据源设置为列名
- python - 从单个列中删除异常值
- r - 如何逐行读取表格 - 使用 R?