用oSql,还原数据库的时候出现下面错误,请问怎么解决?

tafse2004 2005-04-18 04:50:13
我用oSql备份600M的数据库没有问题,还原的时候就出现了下面的错误,不知是什么原因?另外,我备份和还原用的是同一个过程。

osql: 未知选项
用法: osql [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w columnwidth]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-L list servers] [-c cmdend] [-D ODBC DSN name]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-n remove numbering] [-m errorlevel]
[-r msgs to stderr] [-V severitylevel]
[-i inputfile] [-o outputfile]
[-p print statistics] [-b On error batch abort]
[-X[1] disable commands [and exit with warning]]
[-O use Old ISQL behavior disables the following]
<EOF> 批处理
控制台宽度自动调整
宽消息
默认错误级别为 — 1 对 1
[-? show syntax summary]
...全文
194 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
tafse2004 2005-04-20
  • 打赏
  • 举报
回复
企业管理器和小的数据库还原都没有问题,但就是大的数据库就会出现这样的问题,真不知道是为什么?
zjcxc 2005-04-20
  • 打赏
  • 举报
回复
超时?

你试试在命令提示符下,直接调用osql
tafse2004 2005-04-19
  • 打赏
  • 举报
回复
没有错误提示,但pHnd 的值为0,所以它不作操作。
zjcxc 2005-04-19
  • 打赏
  • 举报
回复
在企业管理器中用向导还原看看
zjcxc 2005-04-18
  • 打赏
  • 举报
回复
错误提示是什么?
tafse2004 2005-04-18
  • 打赏
  • 举报
回复
另外,这个问题很是奇怪,我要是还原小的数据库(比如系统自带的数据库)就没有问题,要是还原500M左右的就会出现这情况。
tafse2004 2005-04-18
  • 打赏
  • 举报
回复
Private Function BackupSub(strSQl As String, FileName As String) As Boolean

Dim bfs, bf, bts
Dim pId As Long, pHnd As Long
Dim OSqlPath As String
Dim OSqlAll As String
Dim BakdbPath As String
If Dir(OSqlPath) = "" Then
MsgBox ""
Exit Function
End If
OSqlPath = App.Path & "\BackOrRestoreData\osql.exe"
BakdbPath = App.Path & "\BackOrRestoreData\" & FileName

Set bfs = CreateObject("Scripting.FileSystemObject")
bfs.CreateTextFile BakdbPath
Set bf = bfs.GetFile(BakdbPath)
Set bts = bf.OpenAsTextStream(ForWriting, TristateUseDefault)

bts.Write strSQl
Set bts = Nothing
Set bf = Nothing
Set bfs = Nothing

OSqlAll = OSqlPath & " /U " & frmTest.txt_User.Text & " /P " & frmTest.txt_Pin.Text & " /S " & frmTest.txt_IP.Text & " /i " & BakdbPath
pId = Shell("cmd.exe /c " & OSqlAll, vbHide)
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
If pHnd <> 0 Then
Call WaitForSingleObject(pHnd, INFINITE)
Call CloseHandle(pHnd)
Else
BackupSub = True
End If

End Function
tafse2004 2005-04-18
  • 打赏
  • 举报
回复
这些都是用你的东西,只是我改了一些

iSql = "restore database [" & sDataBaseName & "]" & vbCrLf & _
"from disk='" & sBackUpfileName & "'" & vbCrLf & _
"with file=" & sBackupNumber & vbCrLf
iSql = iSql & IIf(sReplaceExist, ",replace", "")

If BackupSub(iSql, "Restore.sql") = True Then
fRestoreDatabase_a = Error
End If

Private Function BackupSub(strSQl As String, FileName As String) As Boolean

Dim bfs, bf, bts
Dim pId As Long, pHnd As Long ' ·Ö±ðÉùÃ÷ Process Id ¼° Process Handle ±äÊý

Dim OSqlPath As String 'Osql.exeÔÚµ±Ç°³ÌÐòϵķ¾¶
Dim OSqlAll As String
Dim BakdbPath As String 'Bakdb.sqlÔÚµ±Ç°³ÌÐòϵķ¾¶

If Dir(OSqlPath) = "" Then
MsgBox "ÔÚϵͳµÄBackOrRestoreDataĿ¼ÏÂûÓÐÕÒµ½osql.exe±¸·Ý²Ù×÷ÎÞ·¨¼ÌÐø½øÐУ¡", vbExclamation, "Ìáʾ"
Exit Function
End If
OSqlPath = App.Path & "\BackOrRestoreData\osql.exe"
BakdbPath = App.Path & "\BackOrRestoreData\" & FileName

Set bfs = CreateObject("Scripting.FileSystemObject")
bfs.CreateTextFile BakdbPath
Set bf = bfs.GetFile(BakdbPath)
Set bts = bf.OpenAsTextStream(ForWriting, TristateUseDefault)
'дÎļþ BOR_DbName
bts.Write strSQl
Set bts = Nothing
Set bf = Nothing
Set bfs = Nothing

OSqlAll = OSqlPath & " /U " & frmTest.txt_User.Text & " /P " & frmTest.txt_Pin.Text & " /S " & frmTest.txt_IP.Text & " /i " & BakdbPath
pId = Shell("cmd.exe /c " & OSqlAll, vbHide) ' Shell ´«»Ø Process Id
pHnd = OpenProcess(SYNCHRONIZE, 0, pId) ' È¡µÃ Process Handle

If pHnd <> 0 Then
Call WaitForSingleObject(pHnd, INFINITE) ' ÎÞÏ޵ȴý£¬Ö±µ½³ÌÐò½áÊø
Call CloseHandle(pHnd)
Else
BackupSub = True
End If

End Function
zjcxc 2005-04-18
  • 打赏
  • 举报
回复
错误提示是什么?

备份和还原使用同一过程? 那要看你的过程是怎么写的了,备份和还原应用的是不同的处理语句

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧