如何使用 SMO 连接到 Sqlserver2008 必须采取任何解决方法吗?
我写这个是为了在本地计算机上查找 sql server 实例:
using System;
using System.Data;
using Microsoft.SqlServer.Management.Smo;
namespace Application3
{
class Program
{
static void Main(string[] args)
{
string srvname = string.Empty; string srvnames = null;
DataTable dt = SmoApplication.EnumAvailableSqlServers(true);
Console.WriteLine("------------->" + dt.Rows.Count);
foreach (DataRow dr in dt.Rows)
{
try{
Console.WriteLine("-->Instance " + dr["name"]);
Server srv = new Server((string)dr["name"]);
foreach (Database db in srv.Databases)
Console.WriteLine(db.Name);
}catch(Exception e)
{
Console.writeLine(e.toString());
}
}
}
}
我的本地计算机中有 3 个实例
- rk2k3-vm-sr (sql2008 实例)
- rk2k3-vm-sr\sql2k8express (sql2k8 instacne)
- rk2k3-vm-sr\sqlexpress ( sql2k5实例)
但它只显示2和3。1不显示。 当我使用服务器对象连接时,sql2k8express 失败。
这是输出....
-->实例 RK2K3-VM-SR\SQLEXPRESS
大师
型号
数据库数据库
临时数据库
-->实例 RK2K3-VM-SR\SQL2K8EXPRESS
Microsoft.SqlServer.Management.Common.ConnectionFailureException:无法连接 等服务器 RK2K3-VM-SR\SQL2K8EXPRESS。 ---> Microsoft.SqlServer.Management.Com mon.ConnectionFailureException:不支持此 SQL Server 版本 (10.0)。 在 Microsoft.SqlServer.Management.Common.ConnectionManager.CheckServerVersion (服务器版本) 在 Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnect(Wi ndowsIdentity 模拟身份) 在 Microsoft.SqlServer.Management.Common.ConnectionManager.Connect() --- 内部异常堆栈跟踪结束 --- 在 Microsoft.SqlServer.Management.Common.ConnectionManager.Connect() 在 Microsoft.SqlServer.Management.Common.ConnectionManager.PoolConnect() 在 Microsoft.SqlServer.Management.Common.ConnectionManager.get_ServerVersion( ) 在 Microsoft.SqlServer.Management.Smo.ExecutionManager.get_ServerVersion() 在 Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetDbComparer(Boolean inSe 河) 在 Microsoft.SqlServer.Management.Smo.SqlSmoObject.InitializeStringComparer() 在 Microsoft.SqlServer.Management.Smo.AbstractCollectionBase.get_StringCompar 呃() 在 Microsoft.SqlServer.Management.Smo.SimpleObjectCollectionBase.InitInnerCol 朗读() 在 Microsoft.SqlServer.Management.Smo.SmoCollectionBase.get_InternalStorage() 在 Microsoft.SqlServer.Management.Smo.SmoCollectionBase.InitializeChildCollec 化(布尔刷新) 在 Microsoft.SqlServer.Management.Smo.SmoCollectionBase.GetEnumerator() 在 C:\Documents 和 Settin 中的 ConsoleApplication3.Program.Main(String[] args) gs\Administrator.APP\Desktop\ConsoleApplication3\Program.cs:第 25 行
行 我该如何解决此问题? 我的系统防火墙已禁用,所有 sql 服务都在运行。
I wrote this for finding the sql server instances on the local machine:
using System;
using System.Data;
using Microsoft.SqlServer.Management.Smo;
namespace Application3
{
class Program
{
static void Main(string[] args)
{
string srvname = string.Empty; string srvnames = null;
DataTable dt = SmoApplication.EnumAvailableSqlServers(true);
Console.WriteLine("------------->" + dt.Rows.Count);
foreach (DataRow dr in dt.Rows)
{
try{
Console.WriteLine("-->Instance " + dr["name"]);
Server srv = new Server((string)dr["name"]);
foreach (Database db in srv.Databases)
Console.WriteLine(db.Name);
}catch(Exception e)
{
Console.writeLine(e.toString());
}
}
}
}
I have 3 instances in my local machine
- rk2k3-vm-sr (sql2008 instance)
- rk2k3-vm-sr\sql2k8express (sql2k8 instacne)
- rk2k3-vm-sr\sqlexpress (sql2k5 instance)
But it is only showing 2 and 3. 1 does not show. And when I connect using server object it fails for sql2k8express.
Here is the Output....
-->Instance RK2K3-VM-SR\SQLEXPRESS
master
model
msdb
tempdb
-->Instance RK2K3-VM-SR\SQL2K8EXPRESS
Microsoft.SqlServer.Management.Common.ConnectionFailureException: Failed to conn
ect to server RK2K3-VM-SR\SQL2K8EXPRESS. ---> Microsoft.SqlServer.Management.Com
mon.ConnectionFailureException: This SQL Server version (10.0) is not supported.
at Microsoft.SqlServer.Management.Common.ConnectionManager.CheckServerVersion
(ServerVersion version)
at Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnect(Wi
ndowsIdentity impersonatedIdentity)
at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
at Microsoft.SqlServer.Management.Common.ConnectionManager.PoolConnect()
at Microsoft.SqlServer.Management.Common.ConnectionManager.get_ServerVersion(
)
at Microsoft.SqlServer.Management.Smo.ExecutionManager.get_ServerVersion()
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetDbComparer(Boolean inSe
rver)
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.InitializeStringComparer()
at Microsoft.SqlServer.Management.Smo.AbstractCollectionBase.get_StringCompar
er()
at Microsoft.SqlServer.Management.Smo.SimpleObjectCollectionBase.InitInnerCol
lection()
at Microsoft.SqlServer.Management.Smo.SmoCollectionBase.get_InternalStorage()
at Microsoft.SqlServer.Management.Smo.SmoCollectionBase.InitializeChildCollec
tion(Boolean refresh)
at Microsoft.SqlServer.Management.Smo.SmoCollectionBase.GetEnumerator()
at ConsoleApplication3.Program.Main(String[] args) in C:\Documents and Settin
gs\Administrator.APP\Desktop\ConsoleApplication3\Program.cs:line 25
How can i fix this? My System firewall is disabled and all sql services are running.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码是以前为 SQL 2005 编写的吗?
如果是,您需要
删除对 SLQ 2005 和 SLQ 2005 的 SDK dll 的引用 重新参考 SQL 2008 的 SK Dlls。
(http://msdn.microsoft.com/en-us/library/ms162129 .aspx)
重建。
另请参阅:应用程序找不到 Microsoft.SQLServer.SMO在 SQL 2008 机器上
Is this code previously written for SQL 2005?
If yes you need to
Install SQL 2005 Backwards Compatibilty Pack for SQL 2008 + Management Objects on the machine. (http://www.microsoft.com/downloads/details.aspx?FamilyID=b33d2c78-1059-4ce2-b80d-2343c099bcb4&displaylang=en)
Remove references to SDK dlls of SLQ 2005 & re reference to SK Dlls of SQL 2008.
(http://msdn.microsoft.com/en-us/library/ms162129.aspx)
Rebuild.
Also refer to: Application cannot find Microsoft.SQLServer.SMO on SQL 2008 machine