303factory
Registered User.
- Local time
- Today, 07:11
- Joined
- Oct 10, 2008
- Messages
- 136
Hi all
We have recently moved our database onto a WAN, with the database server now being located in a different city to me.
The problem is that (apparently) due to network lag my code seems to be running very slowly. My client has to read several thousand entries in an XML file and write it into our database. Until now I've been doing this by opening an ADODB recordset and adding the data line by line.
This has always ran very quickly (several thousand entries in a few minutes) but now takes well over half an hour to do the same operation. The network team inform me that the method I use is encountering the network lag for every new line added and I need to find a way to upload all the data in one move.
Below is (a cut down for example) version of my code. We're running an SQL Server 2008 back end with linked tables, and communicating with an SQL Server Native Client 10.0 ODBC. Unfortunately I'm quite new to SQL Server and am not an experienced programmer so am looking for advice for a different method to use. I have a very limited timescale so can't afford to spend time testing/researching alternatives, but if someone knows why this is a slow method to use and could point me in the right direction it would be massively appreciated.
We have recently moved our database onto a WAN, with the database server now being located in a different city to me.
The problem is that (apparently) due to network lag my code seems to be running very slowly. My client has to read several thousand entries in an XML file and write it into our database. Until now I've been doing this by opening an ADODB recordset and adding the data line by line.
This has always ran very quickly (several thousand entries in a few minutes) but now takes well over half an hour to do the same operation. The network team inform me that the method I use is encountering the network lag for every new line added and I need to find a way to upload all the data in one move.
Below is (a cut down for example) version of my code. We're running an SQL Server 2008 back end with linked tables, and communicating with an SQL Server Native Client 10.0 ODBC. Unfortunately I'm quite new to SQL Server and am not an experienced programmer so am looking for advice for a different method to use. I have a very limited timescale so can't afford to spend time testing/researching alternatives, but if someone knows why this is a slow method to use and could point me in the right direction it would be massively appreciated.
Code:
' SQL Connection
Set gSQLdbase = New ADODB.Connection
gSQLdbase.ConnectionString = "Provider=SQLNCLI10;Data Source=[ip],[port];Network Library=DBMSSOCN;Initial Catalog=[odbcName];uid=[username];pwd=[password];"
Case "MID Client SQL SOCA.mdb"
gSQLdbase.Open
Dim rstRS As ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM tblMessages WHERE 1=0"
Set rstRS = New ADODB.Recordset
rstRS.Open strSQL, gSQLdbase, adOpenKeyset, adLockOptimistic, adCmdText
intRegNumber = 0
strMessages = MESSAGES & "[" & intRegNumber & "]"
Set objNode = objXMLFile.selectSingleNode(strMessages)
Do Until objNode Is Nothing
With rstRS
.AddNew
.Fields("Message") = objXMLFile.selectSingleNode([nodelocation])
[same as above line for about 10 other fields)
End With
intRegNumber = intRegNumber + 1
strMessages = MESSAGES & "[" & intRegNumber & "]"
Set objNode = objXMLFile.selectSingleNode(strMessages)
Loop
If Not rstRS.EOF Then rstRS.Update
rstRS.Close
Set rstRS = Nothing