T-sql脚本保存成*.sql文档,有没有办法直接在应用程序里直接调用该脚本执行?谢谢各位大虾^_^

解决方案 »

  1.   

    9494把文件读到sql字符串中执行
      

  2.   

    open("osql -Sserver -Ppassword -Usa -ddatebase -ifile.sql");
    注意:区分大小写
      

  3.   

    '以下代码,仅供参考
    Public Function BuildData(ByVal SQLPath_File As String, ByVal strServerName As String, ByVal strLoginID As String, ByVal strPassword As String)
        Dim l_str_sql       As String
        Dim l_str_Line      As String
        Dim l_int_FileNum   As Integer
        Dim l_str_SqlView   As String
        Dim t_conDb As New ADODB.Connection
        Dim strCon As String
        Dim rstTmp As New ADODB.Recordset
        Dim strDiskID As String
       
        Dim strcoName  As String
        Dim strSerial As String
        Dim strRegDate As Date
        Dim strEndDate As Date
        Dim lngZong As Long
       
       'On Error GoTo PROC_ERR
          strCon = "Driver={SQL Server}" & _
                ";Server=" & strServerName & _
                ";database=Master" & _
                ";uid=" & strLoginID & "" & _
                ";pwd=" & strPassword
                
       t_conDb.CursorLocation = adUseClient
       t_conDb.CommandTimeout = 30
       t_conDb.ConnectionString = strCon
       t_conDb.Open
       t_conDb.Execute "  CREATE DATABASE kysL "
       strCon = "Driver={SQL Server}" & _
                ";Server=" & strServerName & _
                ";database=kysl" & _
                ";uid=" & strLoginID & "" & _
                ";pwd=" & strPassword
       t_conDb.Close
       t_conDb.ConnectionString = strCon
       t_conDb.Open
        Screen.MousePointer = vbHourglass
        
    On Error Resume Next
        
        l_int_FileNum = FreeFile
        l_str_sql = ""
        Open SQLPath_File For Input As #l_int_FileNum
            
            Do Until EOF(l_int_FileNum)
                Line Input #l_int_FileNum, l_str_Line
                
                If UCase(Trim(l_str_Line)) = "GO" Then
                    If InStr(1, l_str_sql, "*/") = 0 Then
                        l_str_SqlView = Trim(l_str_sql)
                    Else
                        l_str_SqlView = Trim(Mid(l_str_sql, InStr(1, l_str_sql, "*/") + 2))
                    End If
                   
                    
                    t_conDb.Execute l_str_sql, , adCmdText + adExecuteNoRecords
                    l_str_sql = ""
                Else
                    l_str_sql = l_str_sql + l_str_Line
                End If
            Loop
            
        
        Close #l_int_FileNum    Screen.MousePointer = vbDefault
        
        
        Exit Function
        
    ErrTrans:
        
        Screen.MousePointer = vbDefaultEnd Function
      

  4.   

    to  windindance(风舞轻扬) :
    是用什么open啊?connection or recordset? 谢谢啦~~~~
      

  5.   

    不是,我记错了,用ShellEXecute调用外部程序osql去执行。
      

  6.   

    to  windindance(风舞轻扬) :
    -S、-P等后面是否要加双引号?
    俺的服务器名称是abc
    用户sa ,无密码,
    数据库PHTest象俺下面这样对不对?Dim rst As New ADODB.Recordset
    Set rst.ActiveConnection = cnn
    rst.Open ("osql -Sabc -P -Usa -dPHTest -iD:\test\Query.sql")鞠躬:):)
      

  7.   

    读进来,然后在ado中把它当成存储过程来执行....
      

  8.   

    严重感谢各位,最后采用的解决方法是:用isql.exe调用脚本处理,采用批处理文件
    isql -S abc -U sa -P  -d test -i D:\temp\Update.sql参数说明如下:
    -S :服务器名称;
    -U :用户名;
    -P :密码;
    -d :数据库名称;
    -i :sql脚本路径;最后用rar制作安装文件执行。