如何使用SMO连接到Sqlserver2008任何解决方法必须完成? [英] How to Connect to Sqlserver2008 using SMO any workaround has to be done?

查看:350
本文介绍了如何使用SMO连接到Sqlserver2008任何解决方法必须完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个在本地机器上查找sql​​ server实例:

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());
            }
        }
    }
}



在我的本机中有3个实例

I have 3 instances in my local machine


  1. rk2k3-vm-sr(sql2008 instance)

  2. rk2k3 -vm-sr \sql2k8express(sql2k8 instacne)

  3. rk2k3-vm-sr\sqlexpress(sql2k5 instance)

但它只显示2和3. 1不显示。当我使用服务器对象连接时,它对sql2k8express失败。

But it is only showing 2 and 3. 1 does not show. And when I connect using server object it fails for sql2k8express.

这是输出....


- >实例RK2K3-VM-SR\SQLEXPRESS

主档

模型

msdb

tempdb

-->Instance RK2K3-VM-SR\SQLEXPRESS
master
model
msdb
tempdb








- >实例RK2K3-VM-SR \SQL2K8EXPRESS

-->Instance RK2K3-VM-SR\SQL2K8EXPRESS

Microsoft.SqlServer.Management.Common.ConnectionFailureException:无法连接到服务器RK2K3-VM-SR \SQL2K8EXPRESS。 ---> Microsoft.SqlServer.Management.Com
mon.ConnectionFailureException:不支持此SQL Server版本(10.0)。
at Microsoft.SqlServer.Management.Common.ConnectionManager.CheckServerVersion
(ServerVersion版本)
在Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnect(Wi
ndowsIdentity impersonatedIdentity)
at 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()
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()
在Microsoft.SqlServer.Management.Smo.SimpleObjectCollectionBase.InitInnerCol
lection()
在Microsoft.SqlServer.Management.Smo.SmoCollectionBase.get_InternalStorage()
在Microsoft.SqlServer.Management.Smo.SmoCollectionBase.InitializeChildCollec
tion(布尔刷新)
在Microsoft.SqlServer。在C:\Documents和Settin
中的ConsoleApplication3.Program.Main(String [] args)中的Management.Smo.SmoCollectionBase.GetEnumerator()
gs \Administrator.APP\Desktop\ConsoleApplication3\\ \\Program.cs:line 25

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

如何解决这个问题?我的系统防火墙已禁用,所有sql服务都正在运行。

How can i fix this? My System firewall is disabled and all sql services are running.

推荐答案


如果是,您需要

Is this code previously written for SQL 2005? If yes you need to


  1. 在机器上安装用于SQL 2008 +管理对象的SQL 2005向后兼容包。 ( http:// www .microsoft.com / downloads / details.aspx?FamilyID = b33d2c78-1059-4ce2-b80d-2343c099bcb4& displaylang = en

移除参考SLQ 2005&请参阅SQL 2008的SK Dll。
http:// msdn.microsoft.com/en-us/library/ms162129.aspx

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)

重建。

另请参阅:应用程序在SQL 2008机器上找不到Microsoft.SQLServer.SMO

这篇关于如何使用SMO连接到Sqlserver2008任何解决方法必须完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆