R
Radu
Hi.
My site's users will upload some "PIN" excel files. On receiving them,
I have to investigate their structure, and if correct, load their
contents into a db table for further processing (inside the db).
The excel file contains, say, 10 records only, and looks like this:
PIN Grouping
0 A
1 A
2 B
3 B
4 V
....................................
9 X
For a specific instance, the ASP code saves the uploaded file as, for
example, "Pin List Sample A1.xls", on a share visible both by me and
by the IIS account, of course.
The sproc named "InputPins_InsertExcelFileIntoRequestedPINS" has to
insert the contents of the excel file into a db table, and is simple.
It contains 4 parameters:
@SessionID varchar(50),
@Filename varchar(200),
@Workbook varchar(200),
@Language varchar(5)
Then I build the following string (simplified):
SELECT [PIN],
a few other fields...,
'Excel' as [Source]
FROM
OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="//.../
Pin List
Sample A1.xls";Extended properties=Excel 8.0')...ABC$ WHERE NOT PIN
IS
NULL ORDER BY [Grouping]
Finally the sproc says:
INSERT INTO RequestedPINS EXEC(@SQLString)
All's well. If I run in QueryAnalyzer the following:
exec InputPins_InsertExcelFileIntoRequestedPINS
@SessionID=N'enarct454plep145islfwu55',
@Filename=N'//.../Pin List Sample A1.xls',
@Workbook=N'ABC$',
@Language=N'EN-CA'
the query returns in a few milliseconds, and works fine - I can see
the 10 records in the table RequestedPINS.
Now, asp.net. I run the following simple code:
......................
cnSQL.Open()
cmd = New SqlCommand
("InputPins_InsertExcelFileIntoRequestedPINS", cnSQL)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@SessionID", Session
("SessionID").ToString))
cmd.Parameters.Add(New SqlParameter("@Filename",
strTableName))
cmd.Parameters.Add(New SqlParameter("@Workbook",
strSheetName))
If Session("Language") Is Nothing Then
Session("Language") = "EN-CA"
End If
cmd.Parameters.Add(New SqlParameter("@Language", Session
("Language").ToString))
cmd.ExecuteNonQuery()
cnSQL.Close()
This executes equally well, but requires 12 seconds ! Executing this
sproc from asp.net takes 12
seconds compared to 50 milliseconds in QA - that's a factor of
240 !!!
Since the website is designed as a "wizard", with many data-acquiring
steps/pages, it has to be synchroneous - I cannot go onto the next
page until the excel file is uploaded and its data processed. Note
that all the other sprocs used by this application (and there are
many) execute perfectly - it's only this one which becomes extremely
slow. What can it be ? I have profiled it, but maybe I don't know what
to look for... the fact is that it takes 240 times longer to execute
it from the website than from the QA. What could it be ? Does this
relate solely to SQL Server ?
Thank you very much,
Alex
My site's users will upload some "PIN" excel files. On receiving them,
I have to investigate their structure, and if correct, load their
contents into a db table for further processing (inside the db).
The excel file contains, say, 10 records only, and looks like this:
PIN Grouping
0 A
1 A
2 B
3 B
4 V
....................................
9 X
For a specific instance, the ASP code saves the uploaded file as, for
example, "Pin List Sample A1.xls", on a share visible both by me and
by the IIS account, of course.
The sproc named "InputPins_InsertExcelFileIntoRequestedPINS" has to
insert the contents of the excel file into a db table, and is simple.
It contains 4 parameters:
@SessionID varchar(50),
@Filename varchar(200),
@Workbook varchar(200),
@Language varchar(5)
Then I build the following string (simplified):
SELECT [PIN],
a few other fields...,
'Excel' as [Source]
FROM
OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="//.../
Pin List
Sample A1.xls";Extended properties=Excel 8.0')...ABC$ WHERE NOT PIN
IS
NULL ORDER BY [Grouping]
Finally the sproc says:
INSERT INTO RequestedPINS EXEC(@SQLString)
All's well. If I run in QueryAnalyzer the following:
exec InputPins_InsertExcelFileIntoRequestedPINS
@SessionID=N'enarct454plep145islfwu55',
@Filename=N'//.../Pin List Sample A1.xls',
@Workbook=N'ABC$',
@Language=N'EN-CA'
the query returns in a few milliseconds, and works fine - I can see
the 10 records in the table RequestedPINS.
Now, asp.net. I run the following simple code:
......................
cnSQL.Open()
cmd = New SqlCommand
("InputPins_InsertExcelFileIntoRequestedPINS", cnSQL)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@SessionID", Session
("SessionID").ToString))
cmd.Parameters.Add(New SqlParameter("@Filename",
strTableName))
cmd.Parameters.Add(New SqlParameter("@Workbook",
strSheetName))
If Session("Language") Is Nothing Then
Session("Language") = "EN-CA"
End If
cmd.Parameters.Add(New SqlParameter("@Language", Session
("Language").ToString))
cmd.ExecuteNonQuery()
cnSQL.Close()
This executes equally well, but requires 12 seconds ! Executing this
sproc from asp.net takes 12
seconds compared to 50 milliseconds in QA - that's a factor of
240 !!!
Since the website is designed as a "wizard", with many data-acquiring
steps/pages, it has to be synchroneous - I cannot go onto the next
page until the excel file is uploaded and its data processed. Note
that all the other sprocs used by this application (and there are
many) execute perfectly - it's only this one which becomes extremely
slow. What can it be ? I have profiled it, but maybe I don't know what
to look for... the fact is that it takes 240 times longer to execute
it from the website than from the QA. What could it be ? Does this
relate solely to SQL Server ?
Thank you very much,
Alex