G
Guest
I am having difficulty sending an update of 20,000 rows to an SQL server.
When I use sqlCommandBuiilder to create the update command the update takes
less than a minute. When I manually build the command and the parameters
the update is taking closer to 20 minutes. I have had the same experience
using a stored procedure to perform the update or putting the SQL update
statement in the sqlcommand object. Any thoughts on what could cause such a
difference in performance?
Some facts. I'm updating a single table with almost 20,000 rows and 10
columns. I am only updating two of the columns for each record. I am using
an Identity column in my where statement.
C# code.
//Stored Procedure
SqlCommand updateCmd = new SqlCommand("UpdateDeviceListStatus",
this.getConnection());
updateCmd.CommandType = CommandType.StoredProcedure;
updateCmd.Parameters.Add(new SqlParameter("@deviceStatus",
SqlDbType.VarChar));
updateCmd.Parameters["@deviceStatus"].SourceColumn = "deviceStatus";
updateCmd.Parameters["@deviceStatus"].Size = 250;
updateCmd.Parameters.Add(new SqlParameter("@deviceResponsetime",
SqlDbType.BigInt));
updateCmd.Parameters["@deviceResponseTime"].SourceColumn =
"deviceResponseTime";
updateCmd.Parameters.Add(new SqlParameter("@deviceID", SqlDbType.BigInt));
updateCmd.Parameters["@deviceID"].SourceColumn = "deviceID";
dsCmd.UpdateCommand = updateCmd;
//Update DB with dataset
dsCmd.Update(dtable);
SQL Stored Procedure.
CREATE PROCEDURE dbo.UpdateDeviceListStatus
(
@deviceID bigint, @deviceStatus varchar(250), @deviceResponseTime bigint
)
AS UPDATE deviceList
SET deviceStatus = @deviceStatus, deviceResponseTime = @deviceResponseTime
WHERE (deviceID = @deviceID)
RETURN
GO
When I use sqlCommandBuiilder to create the update command the update takes
less than a minute. When I manually build the command and the parameters
the update is taking closer to 20 minutes. I have had the same experience
using a stored procedure to perform the update or putting the SQL update
statement in the sqlcommand object. Any thoughts on what could cause such a
difference in performance?
Some facts. I'm updating a single table with almost 20,000 rows and 10
columns. I am only updating two of the columns for each record. I am using
an Identity column in my where statement.
C# code.
//Stored Procedure
SqlCommand updateCmd = new SqlCommand("UpdateDeviceListStatus",
this.getConnection());
updateCmd.CommandType = CommandType.StoredProcedure;
updateCmd.Parameters.Add(new SqlParameter("@deviceStatus",
SqlDbType.VarChar));
updateCmd.Parameters["@deviceStatus"].SourceColumn = "deviceStatus";
updateCmd.Parameters["@deviceStatus"].Size = 250;
updateCmd.Parameters.Add(new SqlParameter("@deviceResponsetime",
SqlDbType.BigInt));
updateCmd.Parameters["@deviceResponseTime"].SourceColumn =
"deviceResponseTime";
updateCmd.Parameters.Add(new SqlParameter("@deviceID", SqlDbType.BigInt));
updateCmd.Parameters["@deviceID"].SourceColumn = "deviceID";
dsCmd.UpdateCommand = updateCmd;
//Update DB with dataset
dsCmd.Update(dtable);
SQL Stored Procedure.
CREATE PROCEDURE dbo.UpdateDeviceListStatus
(
@deviceID bigint, @deviceStatus varchar(250), @deviceResponseTime bigint
)
AS UPDATE deviceList
SET deviceStatus = @deviceStatus, deviceResponseTime = @deviceResponseTime
WHERE (deviceID = @deviceID)
RETURN
GO