如何使用SMO的任何解决方法连接到SQLServer2008的已经做? [英] How to Connect to Sqlserver2008 using SMO any workaround has to be done?

查看:465
本文介绍了如何使用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实例)
  2. rk2k3-VM-SR \ sql2k8ex preSS(sql2k8 instacne)
  3. rk2k3-VM-SR \ sqlex preSS(sql2k5实例)

但它是仅示出2和3 1不显示。当我连接使用服务器对象失败的sql2k8ex preSS。

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 \ SQLEX $ P $干燥综合征
  主
  模型
  MSDB
  tempdb中

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


- >实例RK2K3-VM-SR \ SQL2K8EX $ P $干燥综合征

-->Instance RK2K3-VM-SR\SQL2K8EXPRESS

Microsoft.SqlServer.Management.Common.ConnectionFailureException:未能conn将   等服务器RK2K3-VM-SR \ SQL2K8EX $ P $干燥综合征。 ---> Microsoft.SqlServer.Management.Com   不支持此SQL Server版本(10.0):mon.ConnectionFailureException。      在Microsoft.SqlServer.Management.Common.ConnectionManager.CheckServerVersion   (ServerVersion版)      在Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnect(无线   ndowsIdentity impersonatedIdentity)      在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(布尔樱雪   rver)      在Microsoft.SqlServer.Management.Smo.SqlSmoObject.InitializeStringComparer()      在Microsoft.SqlServer.Management.Smo.AbstractCollectionBase.get_StringCompar   ER()      在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()      在ConsoleApplication3.Program.Main(字串[] args)在C:\ Documents和设置搜索   GS \ Administrator.APP \桌面\ ConsoleApplication3 \的Program.cs:行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.

推荐答案

这是code previously为SQL 2005写的? 如果是的话,你需要

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

  1. 本机上的SQL 2008 +管理对象安装SQL 2005向后兼容性包。 (<一href="http://www.microsoft.com/downloads/details.aspx?FamilyID=b33d2c78-1059-4ce2-b80d-2343c099bcb4&displaylang=en" rel="nofollow">http://www.microsoft.com/downloads/details.aspx?FamilyID=b33d2c78-1059-4ce2-b80d-2343c099bcb4&displaylang=en)

删除引用到2005年SLQ和放大器的SDK DLL文件;再参考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)

重建。

另请参考:<一href="http://stackoverflow.com/questions/1067818/application-cannot-find-microsoft-sqlserver-smo-on-sql-2008-machine">http://stackoverflow.com/questions/1067818/application-cannot-find-microsoft-sqlserver-smo-on-sql-2008-machine

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

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