Database=xxx;User ID=xxx;Password=xxx;
为什么此连接字符串在没有指定服务器/数据源的情况下工作。此连接的MS SQL Server(在本地运行)从Windows App
private static string connectionstr = "Database=xxx; User ID=xxx; Password=xxx;";
public void connect()
{
scon = new SqlConnection(connectionstr);
scon.Open();
}
使用没有DataSource
的连接字符串创建SqlConnection
会导致默认值,该值是一个空字符串(")。
空字符串(")将在稍后翻译为localhost
,从cmd
尝试ping ""
,然后看到您实际pinging localhost
。
参见MSDN SQLConnection,备注部分-DataSource
初始值是empty string ("")
默认主机名是您的localhost。