读书人

【MSSQL2008-SMO异常】

发布时间: 2012-12-22 12:05:06 作者: rapoo

【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


C:\Users\poofly\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs(17,13): 错误 CS0012: 类型“Microsoft.SqlServer.Management.Sdk.Sfc.ISfcValidate”在未被引用的程序集中定义。必须添加对程序集“Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91”的引用。
e:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll: (相关文件)


关键错误好像出现在 Server这个类上 说没引用XXXXXXXXXXXXXXXXX

跪求答案~~~

ps:我的机器上有 2005的EXPRESS 2008的企业版

[最优解释]
1).
你要再引用
Microsoft.SqlServer.Manangement.Sdk.sfc 这个DLL

2).
然后还要一句sc.Connect();

  static void Main(string[] args)
{
Server s = new Server("POOFLY-PC");
ServerConnection sc = s.ConnectionContext;
sc.LoginSecure = false;
sc.Login = "sa";
sc.Password = "123456";
sc.Connect(); //add this line

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");

}

[其他解释]
我把SQL2005关闭了。。

sQL2008服务都开了
还是不行
[其他解释]
不懂帮顶..
[其他解释]
不懂帮顶
[其他解释]
引用:
1).
你要再引用
Microsoft.SqlServer.Manangement.Sdk.sfc 这个DLL

2).
然后还要一句sc.Connect();

C# code
static void Main(string[] args)
{
Server s = new Server("POOFLY-PC");
……

第一步的引用如何做
using Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91;??
不好意思 .net 不是很熟悉
[其他解释]
在C# Express直接添加引用就好。


命令行的有些繁琐:

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.Management.Sdk.Sfc.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
[其他解释]

引用:
在C# Express直接添加引用就好。

命令行的有些繁琐:

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……

我关了2005 express的服务
用2008
我dll文件是找到了。。
嘻嘻 就是不知道怎么直接引用。。。

[其他解释]
汗。。。

你是在记事本里写好程序,然后命令行调用csc.exe编译吗? 是的话试试#6楼的


如果是C# 2008 Express工具写,那就更简单了,直接添加引用就好了呀。
[其他解释]
引用:
汗。。。

你是在记事本里写好程序,然后命令行调用csc.exe编译吗? 是的话试试#6楼的


如果是C# 2008 Express工具写,那就更简单了,直接添加引用就好了呀。

嘻嘻 搞好了。。~!多谢KG哥。。
[其他解释]
追求新东西 累呀

读书人网 >SQL Server

热点推荐