我正在写在Visual Studio C#应用程序2015年无法C#应用程序连接到MSSQL
我试图连接到我曾尝试以下远程(异地)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?如果是,那么只是尝试添加持久安全信息= True;到您的连接字符串 –
@AnkitkumarBhatt是的,我使用相同的连接信息。 conn.ConnectionString =“Data Source =#。#。#。#\\ DC3 \\ POS,1433; Network Library = DBMSSOCN; Persist Security Info = True; I nitial Catalog = bDatabase; User ID = [username]; Password = [password]“;' – hinteractive02