c# - SqlBulkCopy to temporary table in SqlServer 2008 -


I have SQL Server need to move large amounts of data in the database 2008 I do I get data from a source server and Sklik BulkCopy is used on the destination server. This data should be parsed from the stored procedure and then deleted. I want to create a temporary data, but if I execute a script does create temp data SqlCommand the client can reach SqlBulkCopy table and works fine, if i server with a stored procedure returns SqlBulkCopy.WriteToServer the Amanyopreshn exception "destination table can not use the '# text is"

this code is fully functional:

  SqlDataReader oSqlDataReader - & gt; Forms Server source Read Oscolik SqlConnection connection = new SqlConnection (_ConnectionTarget) SqlCommand oSqlCommand = new SqlCommand ( "Table #Tax (user id int"), oSqlConnection); OSqlCommand.CommandType = CommandType.Text; OSqlCommand.CommandTimeout = 0; OSqlCommand.ExecuteNonQuery (); SqlBulkCopy oSqlBulkCopy = New SqlBulkCopy (OSQ Connection) oSqlBulkCopy.DestinationTableName = "#Tax"; OSqlBulkCopy.WriteToServer (oSqlDataReader);  

It Amanyopreshn exception exception thrower code:

  SqlDataReader oSqlDataReader - & gt; Read a SqlConnection oSqlConnection = New SqlConnection (_ConnectionTarget) SqlCommand oSqlCommand = New SqlCommand ("SP_CreateTax", oSqlConnection) to the form server; OSqlCommand.CommandType = CommandType.StoredProcedure; OSqlCommand.CommandTimeout = 0; OSqlCommand.ExecuteNonQuery (); SqlBulkCopy oSqlBulkCopy = new SqlBulkCopy (Oskyuknekshn) oSqlBulkCopy.DestinationTableName = "#Tax"; OSqlBulkCopy.WriteToServer (oSqlDataReader);  

SP_CreateTax:

  Create process SP_CreateTax AS Create Start Table #Tax (id int)  
< P>

The problem is that the temporary table created in your stored procedure is valid only within the scope of that stored proc once after doing this, the temporary The table has been deleted.

Create a temporary table in the way you (via the way it works) through inline SQL and proceed.


Comments