Difficulty With Batch Processing Of Scripts
The program currently does this.
Drop triggers
Drop tables
Create tables
Load old data
Convert data
Save data to new database
After that I load up several script files in Query Analyzer and run them to create the triggers.
I would like to get my program to execute the scripts automatically to avoid the last manual step.
This is the code I have to do that.
If Directory.Exists("Scripts") = False Then
Return
End If
Dim files As String() = Directory.GetFiles("Scripts")
For i As Integer = 0 To files.Length - 1
Dim ext As String = files(i).Split(CChar("."))(files(i).Split(CChar(".")).Length - 1)
If ext.ToUpper() <> "SQL" Then
Continue For
End If
Dim script As String = File.ReadAllText(files(i))
Dim result As Integer = New SqlCommand(script, myconnection).ExecuteNonQuery()
If result = 0 Then
Return
End If
Next
Obviously, simple and straight forward. However, whoever is processing the scripts doesn't like them. I'm getting a lot of errors. Here's the first few lines of a script.
USE MyDB
GO
IF OBJECT_ID (N'dbo.Contract_Updated') IS NOT NULL BEGIN
DROP TRIGGER dbo.Contract_Updated
END
GO
First it doesn't like the USE statement. Not a problem. I can comment that out. However, if doesn't like the DROP TRIGGER statement.
Does anyone know how to get the DROP TRIGGER to work. Also, does anyone know of a reference that I can use to modify my scripts to work when executed by my program.
Maybe the problem is how I'm loading the files. Do I need to convert end of line charactors to something else? Or maybe some other issue?
Thanks,
Scott MacMaster

