I need to copy a large set of results from one database and save it in another database.
Stored procedures are used for both retrieval and storage due to the fact that during storage there is some logic.
I am trying to find an effective solution, I cannot store the entire data set in memory, and I would like to minimize the number of visits.
Data is read from the source table using
var reader = fetchCommand.ExecuteReader(); while (reader.Read()){...}
Is there a way to paste this data into another sqlCommand without loading the entire data set into a DataTable , but also without inserting ine rows by one?
Sqlserver is MS SQL Server 2008 for both source and target databases. Databases are located on different servers. Using SSIS or linked servers is not an option.
EDIT: It appears that the string flows into the stored procedure can be used using table parameters . Will also explore this approach.
UPDATE: Yes, it is possible to transfer data from command.ExecuteReader to another command as follows:
var reader = selectCommand.ExecuteReader(); insertCommand.Parameters.Add( new SqlParameter("@data", reader) {SqlDbType = SqlDbType.Structured} ); insertCommand.ExecuteNonQuery();
Where insertCommand is the stored procedure with the @data table @data .
source share