Updating SQL database table using webservice
I have a problem and I have been looking at the internet for a long and long time, but I couldn't find anything.
I have a small application that sucks in a web service. It then passes the results of other applications to these web services through its own web service and stores the query in a table.
What I'm trying to do is quickly import the results into a table from a dataset.
Option 1 is that I loop through all the rows in the dataset and use every insert. The problem with this is that the web service of small applications is slow and will slow down.
Option 2 is bulk loading the dataset into sql. Bad news for me - I don't know how! Can anyone please help?
a source to share
You can use SqlBulkCopy . A simple SqlBulkCopy might look like this:
DataTable dtMyData = ... retrieve records from WebService
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString)) {
bulkCopy.BulkCopyTimeout = 120; // timeout in seconds, default is 30
bulkCopy.DestinationTableName = "MyTable";
bulkCopy.WriteToServer(dtMyData);
}
If you are handling a large amount of data, you can also set the BatchSize property .
a source to share
Using bulk loading can be a pain for a variety of reasons, starting with how you do it is specific to your DBMS. (The next thing that usually gets you is where the data file should go.)
However, you can significantly increase performance in portable mode by simply executing all of yours INSERT
in one transaction:
BEGIN TRANSACTION
INSERT ...
INSERT ...
...
COMMIT TRANSACTION
a source to share
If time is on your side, you can learn to use SQL Server Service Broker technology, but the learning curve is quite steep initially.
http://msdn.microsoft.com/en-us/library/ms166043(SQL.90).aspx
You can create a web service that runs a stored procedure function to insert the results of your process.
a source to share