1

我在使用传输类传输带有数据的数据库时遇到问题。它工作正常,无需传输数据。有了我得到的数据

错误:错误代码 = -1071636471 描述 = SSIS 错误代码 DTS_E_OLEDBERROR。

发生 OLE DB 错误。错误代码 0x800040005/ oledb 记录可用。来源:“Microsoft SQL Server Native Client 10.0” Hresult:0x80004005 描述:2登录失败。登录来自不受信任的域,不能与 Windows 身份验证一起使用”

该类有一个属性transfer.DestinationLoginSecure = false;,当设置为 false 时,不使用集成安全性。我尝试设置各种属性无济于事。

在我使用它的所有其他实例中连接良好的连接字符串。

  using (SqlConnection conn = new SqlConnection(Connections.dbConnection_HTOUTER()))
            {
                conn.Open();
                Server server = new Server(new ServerConnection(conn));
                Database dbMaster = server.Databases[ConfigurationManager.AppSettings.Get("dbMaster")];
                Database dbProduction = server.Databases[ConfigurationManager.AppSettings.Get("dbProduction")];
                Transfer transfer = new Transfer(dbMaster);

                string login = ConfigurationManager.AppSettings.Get("login");
                string password = ConfigurationManager.AppSettings.Get("password");

                transfer.CopyAllObjects = true;
                transfer.CopyAllUsers = true;
                transfer.Options.WithDependencies = true;
                transfer.Options.ContinueScriptingOnError = true;

                transfer.DestinationServer = server.Name;
                transfer.DestinationDatabase = dbProduction.Name;
                transfer.DestinationLoginSecure = false;
                transfer.DestinationPassword = password;
                transfer.DestinationLogin = login;

                transfer.CopyAllRules = true;
                transfer.CopyAllRoles = true;

                //transfer.CopyAllObjects = true;

                transfer.DropDestinationObjectsFirst = true;
                transfer.CopySchema = true;
                transfer.CopyData = true;
                transfer.CreateTargetDatabase = false;
                transfer.Options.IncludeIfNotExists = true;
                transfer.Options.Indexes = true;

                transfer.TransferData();


            }
4

1 回答 1

0

您需要手动设置源服务器和目标服务器的用户、密码。

这将起作用:

SqlConnectionStringBuilder connectionBuilderOriginDatabase = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["ORIGIN"].ConnectionString);

ServerConnection originConnection = new ServerConnection(connectionBuilderOriginDatabase.DataSource);
originConnection.LoginSecure = false;//very important
originConnection.Login = connectionBuilderOriginDatabase.UserID;
originConnection.Password = connectionBuilderOriginDatabase.Password;

Server server = new Server(originConnection);
Database dbMaster = server.Databases[ConfigurationManager.AppSettings.Get("dbMaster")];
Database dbProduction = server.Databases[ConfigurationManager.AppSettings.Get("dbProduction")];
Transfer transfer = new Transfer(dbMaster);

string login = ConfigurationManager.AppSettings.Get("login");
string password = ConfigurationManager.AppSettings.Get("password");

transfer.CopyAllObjects = true;
transfer.CopyAllUsers = true;
transfer.Options.WithDependencies = true;
transfer.Options.ContinueScriptingOnError = true;

//Here you are configuring the destination server
transfer.DestinationServer = server.Name;
transfer.DestinationDatabase = dbProduction.Name;
transfer.DestinationLoginSecure = false;
transfer.DestinationPassword = password;
transfer.DestinationLogin = login;

transfer.CopyAllRules = true;
transfer.CopyAllRoles = true;

//transfer.CopyAllObjects = true;

transfer.DropDestinationObjectsFirst = true;
transfer.CopySchema = true;
transfer.CopyData = true;
transfer.CreateTargetDatabase = false;
transfer.Options.IncludeIfNotExists = true;
transfer.Options.Indexes = true;
于 2016-08-26T00:53:37.280 回答