'以下代码,仅供参考 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
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
to windindance(风舞轻扬) : 是用什么open啊?connection or recordset? 谢谢啦~~~~
不是,我记错了,用ShellEXecute调用外部程序osql去执行。
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")鞠躬:):)
注意:区分大小写
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
是用什么open啊?connection or recordset? 谢谢啦~~~~
-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")鞠躬:):)
isql -S abc -U sa -P -d test -i D:\temp\Update.sql参数说明如下:
-S :服务器名称;
-U :用户名;
-P :密码;
-d :数据库名称;
-i :sql脚本路径;最后用rar制作安装文件执行。