You must Sign In to post a response.
  • Category: SQL Server

    Data from one table to another

    HI,

    My requirement is I have a table in database in one sql server 1.2.3.4 .

    I want this table data should be automatically gets inserted into another sql server 2.3.4.5 database table (same table as in previous server table).


    How to do this task?


    Regards,
    Ayesha
  • #769774
    you can achieve this with below approaches

    1. Maintain 2 DB server connection string s app.config or web.config file, and connect to 1 st db and get the data into dataset and after another thread create with 2nd DB connection string. take row by row from data set and prepare insert statement and using sqlcommand which is going to create with 2nd DB connection string you will .ExecuteNonQuery

    like that all rows can be copied into 2nd DB

    2. go with SQLbulkCopy and copy all the rows of dataset/data table into 2n DB data table like below

    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
    {
    bulkCopy.DestinationTableName =
    "dbo.tableatDestination";

    try
    {
    // Write from the source to the destination.
    bulkCopy.WriteToServer(ExitingSqlTableName);
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    }

    3. or simple go with Import and Export data feature and do manually exporting data from the 1st DB to 2nd DB using SQL Server Import & Export data feature

    Hope the above will helpful to copy the data .

    Thanks!
    B.Ramana Reddy

  • #769784
    You can also use SQL Server Database Project for this purpose. This allows you to compare and sync two different data sources.


  • Sign In to post your comments