Here is the code that I am using to drop columns from a table. It takes a very long time if there are a lot of records. But with Query Analyser the same query is fast. Can anyone tell what is the problem? Even if I did not create the recordset & used the client side cursor it gave me the problem.
For Each adofld In adoflds
strsql = ""
strsql = "ALTER TABLE [dbo].[" + adorecTablelist("DBTableName"
+ "] DROP COLUMN "
If Left(adofld.Name, 4) = "Old_" Or Left(adofld.Name, 5) = "Flag_" Then
strsql = strsql + Trim(adofld.Name)
Set adorecDropFields = New ADODB.Recordset
adorecDropFields.CursorLocation = adUseServer
adorecDropFields.CursorType = adOpenKeyset
adocnnTargetSetupDB.CommandTimeout = 0
adocnnTargetSetupDB.CursorLocation = adUseServer
Set adorecDropFields = adocnnTargetSetupDB.Execute(strsql)
End If
Next
For Each adofld In adoflds
strsql = ""
strsql = "ALTER TABLE [dbo].[" + adorecTablelist("DBTableName"
If Left(adofld.Name, 4) = "Old_" Or Left(adofld.Name, 5) = "Flag_" Then
strsql = strsql + Trim(adofld.Name)
Set adorecDropFields = New ADODB.Recordset
adorecDropFields.CursorLocation = adUseServer
adorecDropFields.CursorType = adOpenKeyset
adocnnTargetSetupDB.CommandTimeout = 0
adocnnTargetSetupDB.CursorLocation = adUseServer
Set adorecDropFields = adocnnTargetSetupDB.Execute(strsql)
End If
Next