c# - Need help connection with Microsoft.SqlServer.Management.Smo Transfer class -


i trying copy (data, indexes, triggers, stored procedure). 1 database in c#.

here code:

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

i following error:

errorcode=-1071636471 description=ssis error code dts_e_oledberror. ole db error has occurred. error code: 0x80004005.
ole db record available. source: "microsoft sql server native client 10.0" hresult: 0x80004005 description: "login failed user 'domain\user'.".
ole db record available. source: "microsoft sql server native client 10.0" hresult: 0x80004005 description: "cannot open database "mydb(replacing name, correct)" requested login. login failed.".
helpfile= helpcontext=0 idofinterfacewitherror={5bc870eb-bba5-4b9d-a6e3-58c6d0051f14}

the closest have come accomplishing workaround doing:

script = transfer.scripttransfer();  foreach (string s in script) {      //run sqlcommand s } 

but doesn't data.

i have given user every permission can think of both sql server , database itself.

its late body else,

i had same problem , due first line, cast sqlconnection. activates mixed authentication [thats why got error login wrong 'domain\user']

i've choose initialize simple connection using sqlconnectionstringbuilder:

var connectionstring = ((entityconnection)base.referentielcontext.connection).storeconnection.connectionstring; var builder = new sqlconnectionstringbuilder(connectionstring);  var srvconn = new serverconnection         {             serverinstance = builder.datasource,             loginsecure = false,// set true windows authentication             login = builder.userid,             password = builder.password         };  var server = new microsoft.sqlserver.management.smo.server(srvconn); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -