【发布时间】:2017-04-06 07:21:41
【问题描述】:
我正在 Visual Studio 2015 中编写 C# 应用程序。
我正在尝试连接到远程(异地)sql 2008 服务器,我尝试了以下操作:
远程服务器连接已打开
服务器已配置无 TCP 端口。端口行为空白。实际上防火墙已关闭。
我可以远程连接(通过远程桌面)并访问给定 IP 地址上的服务器。
连接字符串 - IP、用户名、密码因明显原因而被删除:
private void button2_Click(object sender, EventArgs e)
{
mssqlConnBtn.Text = "Connecting..";
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=#.#.#.#\\DC3\\POS,1433;Network Library=DBMSSOCN;Initial Catalog=bDatabase;User ID=[username];Password=[password]";
conn.Open();
mssqlConnBtn.Text = "Connected";
}
catch (System.Data.SqlClient.SqlException exsql)
{
MessageBox.Show(exsql.Message);
mssqlConnBtn.Text = "Connect";
}
}
我也试过Data Source=#.#.#.#,1433
错误:
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: TCP Provider, Error:0 - The wait operation timed out.)
这里有什么想法吗?
谢谢!
【问题讨论】:
-
“Visual Basic 2015 中的 C# 应用程序” - 我确定应该是 Visual Studio 2015?
-
您是否使用相同的服务器名称将其与 SQL Server Management Studio 连接?如果是,那么只是尝试添加 Persist Security Info=True;进入你的连接字符串
-
@AnkitkumarBhatt 是的,我使用的是相同的连接信息。我尝试时仍然遇到同样的错误:
conn.ConnectionString = "Data Source=#.#.#.#\\DC3\\POS,1433;Network Library=DBMSSOCN;Persist Security Info=True;Initial Catalog=bDatabase;User ID=[username];Password=[password]"; -
尝试从 Visual Studio Server Explorer 获取连接字符串,我认为应该是正确的
标签: c# sql sql-server sql-server-2008