C# 需要Microsoft.SqlServer.Management.Smo传输类的帮助连接
我试图复制所有内容(数据、索引、触发器、存储过程)。在C#中从一个数据库到另一个数据库 这是我的密码:C# 需要Microsoft.SqlServer.Management.Smo传输类的帮助连接,c#,sql,sql-server,smo,C#,Sql,Sql Server,Smo,我试图复制所有内容(数据、索引、触发器、存储过程)。在C#中从一个数据库到另一个数据库 这是我的密码: SqlConnection connection = new SqlConnection(ConnectionString); Server myServer = new Server(new ServerConnection(connection)); Database db = myServer.Databases[this._myDB]; if (my
SqlConnection connection = new SqlConnection(ConnectionString);
Server myServer = new Server(new ServerConnection(connection));
Database db = myServer.Databases[this._myDB];
if (myServer.Databases[this._newDB] != null)
myServer.Databases[this._newDB].Drop();
Database newdb = new Database(myServer, this._newDB);
newdb.Create();
Transfer transfer = new Transfer(db);
transfer.CopyAllSchemas = false;
transfer.CopyAllStoredProcedures = true;
transfer.CopyAllTables = true;
transfer.CopyAllDatabaseTriggers = true;
transfer.CopyAllObjects = true;
transfer.CopyAllUsers = true;
transfer.Options.WithDependencies = true;
transfer.DestinationDatabase = newdb.Name;
transfer.DestinationServer = myServer.Name;
transfer.DestinationLoginSecure = false;
transfer.DestinationLogin = user;
transfer.DestinationPassword = pwd;
transfer.CopySchema = false;
transfer.CopyData = true;
transfer.Options.DriAll = true;
transfer.Options.Triggers = true;
transfer.Options.WithDependencies = true;
transfer.Options.ContinueScriptingOnError = true;
transfer.TransferData();
我得到以下错误:
errorCode=-1071636471 description=SSIS错误代码DTS_E_OLEDBERROR。发生OLE DB错误。错误代码:0x80004005。OLE DB记录可用。来源:“Microsoft SQL Server本机客户端10.0”Hresult:0x80004005说明:“用户“域\用户”登录失败。”
OLE DB记录可用。来源:“Microsoft SQL Server本机客户端10.0”Hresult:0x80004005说明:“无法打开登录请求的数据库“myDB(替换名称,但它是正确的)”。登录失败。“
helpFile=helpContext=0 idofInterfaceWithError={5BC870EB-BBA5-4B9D-A6E3-58C6D0051F14} 通过解决方法,我最接近于实现这一目标的方法是:
script = transfer.ScriptTransfer();
foreach (string s in script)
{
//run a sqlcommand for s
}
但这并没有得到数据
我已经为用户提供了我所能想到的SQL Server和数据库本身的所有权限。为时已晚,但它可以帮助其他人 我也有同样的问题,这是由于第一行,转换到
SqlConnection
。它会激活混合身份验证[这就是为什么您在登录“域\用户”时出错的原因]
我选择使用SqlConnectionStringBuilder
初始化一个简单连接:
var connectionString = ((EntityConnection)base.ReferentielContext.Connection).StoreConnection.ConnectionString;
var builder = new SqlConnectionStringBuilder(connectionString);
var srvConn = new ServerConnection
{
ServerInstance = builder.DataSource,
LoginSecure = false,// set to true for Windows Authentication
Login = builder.UserID,
Password = builder.Password
};
var server = new Microsoft.SqlServer.Management.Smo.Server(srvConn);
虽然为时已晚,但它可以帮助其他人 我也有同样的问题,这是由于第一行,转换到
SqlConnection
。它会激活混合身份验证[这就是为什么您在登录“域\用户”时出错的原因]
我选择使用SqlConnectionStringBuilder
初始化一个简单连接:
var connectionString = ((EntityConnection)base.ReferentielContext.Connection).StoreConnection.ConnectionString;
var builder = new SqlConnectionStringBuilder(connectionString);
var srvConn = new ServerConnection
{
ServerInstance = builder.DataSource,
LoginSecure = false,// set to true for Windows Authentication
Login = builder.UserID,
Password = builder.Password
};
var server = new Microsoft.SqlServer.Management.Smo.Server(srvConn);
非常感谢。这正是我的问题。谢谢!这正是我的问题。