If want to transfer one or more entitities and their related ones from one sql database to another one.
What would be the easiest way to do this programatically ?
Code sample for code behind copy:
1st. Create a LinqToSQL datacontext containing the table you want to copy. NOTE! If this table has a system generated PK then this might not work.
2nd. The following code will do a copy (Row by Row)
private string FromDBString = "Data Source=DUALCORE\\SQLExpress;Initial Catalog=MusicInfoRationialized;Integrated Security=True";
private string ToDBString = "Data Source=DUALCORE\\SQLEXPRESS;Initial Catalog=TestOfCopyUsingLInq;Integrated Security=True";
private void Button_Click(System.Object sender, System.Windows.RoutedEventArgs e)
FromDBDataContext fromdb = new FromDBDataContext(FromDBString);
object res = from ra in fromdb.RArtistsra200;
FromDBDataContext todb = new FromDBDataContext(ToDBString);
int stp = 1;
The trick to this is to have the same datacontext but using the correct constructor which takes a datasource connection string.
Hope this helps
Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.
Would you like to participate?