当前位置: 代码迷 >> Sql Server >> 【MSSQL2008-SMO异常】
  详细解决方案

【MSSQL2008-SMO异常】

热度:41   发布时间:2016-04-25 01:00:37.0
【MSSQL2008--SMO错误】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management;



namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ServerConnection sc = new ServerConnection("(local)", "sa", "123456");
            sc.LoginSecure = false;
            sc.Login = "sa";
            sc.Password = "123456";
            Console.WriteLine("DatabaseCount:" + "win");

        }
    }
}

上面的代码是成功的

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management;



namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Server s = new Server("POOFLY-PC");
            ServerConnection sc = s.ConnectionContext;
            sc.LoginSecure = false;
            sc.Login = "sa";
            sc.Password = "123456";

            Database db = new Database(s, "newdb");
            db.Create();
            //ServerConnection sc = new ServerConnection("(local)", "sa", "123456");
            //sc.LoginSecure = false;
            //sc.Login = "sa";
            //sc.Password = "123456";
            //Console.WriteLine("DatabaseCount:" + "win");

        }
    }
}

这个就错误了。。。

C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"e:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfo.dll" /reference:"e:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll" /reference:"e:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SmoExtended.dll" /reference:"e:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SqlEnum.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\ConsoleApplication1.exe /target:exe Program.cs Properties\AssemblyInfo.cs