After select the table from one server and how to insert into another server?
I have two servers and I need to transfer all the details of a particular user from one server to another server.
I selected row from one server and now I have to insert into another server of a table.
I selected the row and I return it in datatable.
select *
from [mp_Sites]
where SiteID = "+siteid+"
I called the stored procedure which is present in the server2 for insert into the table which is selected from server1.
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@1", SqlDbType.Int).Value = moduleId;
cmd.Parameters.Add("@2", SqlDbType.VarChar).Value = dtEventsXmls.Rows[i]["SettingName"].ToString();
cmd.Parameters.Add("@3", SqlDbType.VarChar).Value = dtEventsXmls.Rows[i]["SettingValue"].ToString();
cmd.Parameters.Add("@4", SqlDbType.VarChar).Value = dtEventsXmls.Rows[i]["ControlType"].ToString();
cmd.Parameters.Add("@5", SqlDbType.NText).Value = dtEventsXmls.Rows开发者_C百科[i] ["RegexValidationExpression"].ToString();
I think its complicated. Is there a better way of doing it?
You need to define linked server in SQl server. For example LN that you can insert to the linked database. LN.dbo.table . In your store procedure you can insert into linked table
USE full qualified name like
INSERT INTO SERVER1.DATABASE1.dbo.TABLE1 values(SELECT * FROM SERVER2.DATABASE2.dbo.TABLE2)
make sure that no. of columns and dataType should be same of those two tables and order of column value should be same .
精彩评论