传输类的SQL身份验证

本文关键字:身份验证 SQL 传输 | 更新日期: 2023-09-27 18:02:13

我有使用传输类数据传输数据库的问题。它可以在不传输数据的情况下正常工作。有了数据,我得到

ERROR: ERROR code= -1071636471 description = SSIS错误码dtse_oledberror .

发生OLE DB错误。错误码0x800040005/有oledb记录。来源:"Microsoft SQL Server Native Client"10.0" Hresult: 0x80004005描述:2Login failed.日志含义该登录来自不受信任的域,不能与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();

            }

传输类的SQL身份验证

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

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;