Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2003
    Posts
    15

    Talking Unanswered: sql with visual basic

    i've got a script (test.sql) with a couple of queries. I want to run it on a database by just opening a file with a command (like a batch-file or a visual basic script or something). Does anyone know how to do this?

  2. #2
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Wink Just treat it like a .ini file

    ' INI FILE
    [SQL 1]
    SQL1=SELECT * FROM Contacts

    [SQL 2]
    SQL2=SELECT * FROM Business

    'General declarations

    Global GlbSQL1 As String
    Global GlbSQL2 As String
    Global GlbSQL1String As String

    'this is 1 line -->
    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long


    'Module or class

    Public GetString()
    Dim retc As Long
    Dim vPath$ 'pathname
    Dim X As Variant 'Variable
    On Error Resume Next

    DoEvents
    GlbSQL1String = Space(200)
    vPath$ = App.Path & "\SQL.INI"
    retc = GetPrivateProfileString("SQL 1", "SQL1", "?", GlbSQL1String, 200, vPath$)
    DoEvents
    GlbSQL1String= Mid(GlbSQL1String, 1, retc)
    If GlbSQL1String= "?" Then
    MsgBox "Cant vind .ini", vbCritical
    Exit Sub
    End If
    If Len(GlbSQL1String) = 0 Then Exit Sub
    GlbSQL1 = GlbSQL1String

    with me.data1
    .recordsource = GlbSQL1
    .refresh
    end with

    End Sub

  3. #3
    Join Date
    Feb 2002
    Posts
    2,232
    Are these files that were generated using query analyzer ? And do you just want to run the queries - not interacting with the queries ?

  4. #4
    Join Date
    Oct 2003
    Posts
    15
    no i dont want to interact..
    the .sql file only contains create and insert queries

    i want to run this file automaticly during an installation so the database gets created. this way the user of this script doesnt have to start his databasmanager and load the queries

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    You can execute sql files using:

    'osql -S Servername -U sa -P -ic:\SQLScript.sql'

    Use 'osql ?' for help on parameters.

  6. #6
    Join Date
    Feb 2002
    Posts
    2,232
    This is a command-line version - you can also create a stored procedure to execute the file.

  7. #7
    Join Date
    Oct 2003
    Posts
    15
    hey thanks, this works fine on my winXP
    but when i use the command line on a windows 2000 server i get this error:

    'osql' is not recognized as an internal or external command, operable program or batch file.

    you know what the problem is?

  8. #8
    Join Date
    Feb 2002
    Posts
    2,232
    Is sql server installed on that machine ?

  9. #9
    Join Date
    Oct 2003
    Posts
    15
    i have installed a mysql database service on my windows 2000 and the command line doesnt work.

    but if i see your reaction, that command line only works with windows sql server and not with mysql, am i correct?

    do you know a way to get that same command line working for mysql?

  10. #10
    Join Date
    Feb 2002
    Posts
    2,232
    osql is sql server specific. mysql might have a similar way to execute an external sql script.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •