Re: Creation of DSN
From: Al Reid (areidjr_at_reidDASHhome.com)
Date: 05/20/04
- Next message: Val Mazur: "Re: create multiples Stored Procedures usign ADOB command"
- Previous message: Joey T.: "Setting Cache Size?"
- In reply to: DeMoN: "Re: Creation of DSN"
- Next in thread: DeMoN: "Re: Creation of DSN"
- Reply: DeMoN: "Re: Creation of DSN"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 20 May 2004 19:55:26 -0400
Here is what you can do. I assume you are using MSSQL. Each group of
commands are separated by a "GO" command that is interpreted by osql, isql,
query analyzer as a signal to execute the group of commands. so what you
can do is open the sql file and use the Line Input# statement to read the
file.
Build a text string from the input data. when a GO is encountered, do not
append it to the string, rather execute the string that was just built.
Clear the string and continue where you left off. Repeat until the entire
script file has been processed.
Here is something I threw together that seems to work on my machine.
Public Function RunSQLScriptFromFile(ByVal ScriptFileName As String) As
Boolean
On Error GoTo ERROR_HANDLER
Dim strInput As String
Dim strSql As String
Dim cn As ADODB.Connection
Dim lngFreeFile As Long
Set cn = New ADODB.Connection
With cn
.ConnectionString = "Provider=SQLOLEDB.1;Persist Security
Info=False;User ID=Your_UserID;Password = your_password;Initial
Catalog=HealthyEating;Data Source=(local)"
.Open
End With
lngFreeFile = FreeFile
Open ScriptFileName For Input As #lngFreeFile
strSql = ""
Do Until EOF(lngFreeFile)
Line Input #lngFreeFile, strInput
If Not UCase(Trim$(strInput)) = "GO" Then
strSql = strSql & strInput & vbNewLine
Else
cn.Execute strSql
strSql = ""
End If
Loop
RunSQLScriptFromFile = True
Close #lngFreeFile
cn.Close
EXIT_HANDLER:
' Place Procedure Clean-up Code Here
Set cn = Nothing
Exit Function
ERROR_HANDLER:
' Place Error Handler Here
Resume EXIT_HANDLER
End Function
-- Al Reid "It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so." --- Mark Twain "DeMoN" <dabdemon@terra.es> wrote in message news:%23nxk3uqPEHA.1340@TK2MSFTNGP12.phx.gbl... > I'm not doing RecordSets. > > I'm using directly a Command, to execute the creation query. > > I'm trying to automatize a database creation process, and I have to get the > Scripts from a VSS server and execute them into a DB. If I want to make it > "automatically", making that user spends the fewer time possible, I think > that the better way is using VB application. > > I think taht the application would be more difficult that I thought... :S > > Thanks for all anyway. > > I'm happy for have found this forum!! > > > "Al Reid" <areidjr@reidDASHhome.com> escribió en el mensaje > news:OiPcVHpPEHA.644@tk2msftngp13.phx.gbl... > > "DeMoN" <demon_rules@hotmail.com> wrote in message > news:ephVGBpPEHA.2580@TK2MSFTNGP09.phx.gbl... > > > Then, it's impossible to create multiples Stored Procedures using only > one > > > query?? > > > > > > I have to do that, because if I ahve to make a recordset to run each > > > creation script, the performance of the application would be very poor. > > > > > > Thanks > > > > > > > I am not sure what you want to do. However, you do not make Recordsets to > run a creation script. > > > > -- > > Al Reid > > > > "It ain't what you don't know that gets you into trouble. It's what you > know > > for sure that just ain't so." --- Mark Twain > > > > > > > "Al Reid" <areidjr@reidDASHhome.com> wrote in message > > > news:uiWgU8oPEHA.3012@TK2MSFTNGP09.phx.gbl... > > > > "DeMoN" <demon_rules@hotmail.com> wrote in message > > > news:enpSy0oPEHA.3596@tk2msftngp13.phx.gbl... > > > > > Hi again. > > > > > > > > > > I ahve investigating about GO command. > > > > > > > > > > Into SQL help, says taht this command it's available on ODBC > calls. > > > > > > > > > > > > > I am not sure where you got that info. In the SQL Server Books > Online > > > it states: > > > > "Applications based on the DB-Library, ODBC, or OLE DB APIs receive > a > > > syntax error if they attempt to execute a GO command. The SQL > > > > Server utilities never send a GO command to the server." > > > > > > > > Go is only recognized by osql, isql and the query analyzer. > > > > > > > > > I am conecting with the Database using a DNS... > > > > > > > > > > I'm wondering if maybe my problem is raised because the DSN > properties > > > are > > > > > wrong. > > > > > > > > > > Do anyone knows if maybe the GO problem is raised by a bad > > > configuration of > > > > > the DSN. > > > > > > > > > > Thanks > > > > > > > > > > > > > > -- > > > > Al Reid > > > > > > > > "It ain't what you don't know that gets you into trouble. It's what > you > > > know > > > > for sure that just ain't so." --- Mark Twain > > > > > > > > > > > > > > > > > > > >
- Next message: Val Mazur: "Re: create multiples Stored Procedures usign ADOB command"
- Previous message: Joey T.: "Setting Cache Size?"
- In reply to: DeMoN: "Re: Creation of DSN"
- Next in thread: DeMoN: "Re: Creation of DSN"
- Reply: DeMoN: "Re: Creation of DSN"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|