我使用它似乎无法连接到数据库服务器,错误是26号SQL Server管理对象(SMO)有一个应用程序:为什么我不能使用SMO连接到SQL Server?
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
然而,这似乎是唯一的事情,无法连接到数据库。使用下面的作品都没有问题连接到数据库:
- SQL Server Management Studio中
- SQLCMD
System.Data.SqlClient.SqlConnection
- ODBC
- SQLPS模块在PowerShell中
这是我正在使用的代码,当我尝试访问数据库时引发异常,并且据我所知,所有值都是wha牛逼他们应该是:
Server = new SMO.Server(
new ServerConnection(
new SqlConnectionStringBuilder
{
DataSource = ServerName,
InitialCatalog = DatabaseName,
IntegratedSecurity = true
}.ConnectionString));
Database = Server.Databases[DatabaseName];
我发现的唯一的事情是,当我运行sqlcmd -L
没有我的SQL Server实例的显示出来。我基本上希望看到这样的事情:
Servers:
SQL2008
SQL2012
SQL2014
SQL2016
但是,所有这说的是:
Servers:
;UID:Login ID=?;PWD:Password=?;Trusted_Connection:Use Integrated Security=?;*APP:AppName=?;*WSID:WorkStation ID=?;