Jump to content

I have two SQL Servers database  (ServerA, ServerB) with the same database and the same table (Table_Customers).

Now I want to update Table_Customers on ServerB with the data from ServerA. I am doing this in C# and I would like so help to identify what I am doing wrong please.

table.PNG

Link to comment
https://linustechtips.com/topic/744270-oledbtransaction-help/
Share on other sites

Link to post
Share on other sites

You're using the incorrect class to copy the data. You should be using SqlBulkCopy instead of OleDbTransaction.

 

So replacing the line


OleDbTransaction BKD = new OleDbTransaction(DestinationDB);

//with

SqlBulkCopy BKD = new SqlBulkCopy(DestinationDB);

 

Should do the trick. Although I'm not sure how it's going to handle the oledb datareader with the sql connection. If you're using SQL Server, you should be using SqlConnection, SqlTransaction, SqlCommand etc instead of OleDbConnection etc.

 

 

If you look at your errors, the first one in the screenshot shows that OleDbTransaction does not have a constructor with 1 parameter. This indicates that this statement is incorrect: new OleDbTransaction(DestinationDB); Namely, that the number of parameters between the brackets are incorrect. 

The other errors are saying that the type of object you're using doesn't have those properties or functions. This indicates one of two things: You're using the wrong property or method name (typo, completely wrong name etc) or the object type is incorrect.

 

Link to comment
https://linustechtips.com/topic/744270-oledbtransaction-help/#findComment-9433325
Share on other sites

Link to post
Share on other sites

On ‎2‎/‎27‎/‎2017 at 6:06 AM, Seuntjie said:

You're using the incorrect class to copy the data. You should be using SqlBulkCopy instead of OleDbTransaction.

 

So replacing the line

 


OleDbTransaction BKD = new OleDbTransaction(DestinationDB);

//with

SqlBulkCopy BKD = new SqlBulkCopy(DestinationDB);

 

 

Should do the trick. Although I'm not sure how it's going to handle the oledb datareader with the sql connection. If you're using SQL Server, you should be using SqlConnection, SqlTransaction, SqlCommand etc instead of OleDbConnection etc.

 

 

If you look at your errors, the first one in the screenshot shows that OleDbTransaction does not have a constructor with 1 parameter. This indicates that this statement is incorrect: new OleDbTransaction(DestinationDB); Namely, that the number of parameters between the brackets are incorrect. 

The other errors are saying that the type of object you're using doesn't have those properties or functions. This indicates one of two things: You're using the wrong property or method name (typo, completely wrong name etc) or the object type is incorrect.

 

Thanks, will try that

Link to comment
https://linustechtips.com/topic/744270-oledbtransaction-help/#findComment-9441050
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×