下面的腳本基本上採用源表和目標表並複製所有記錄。它工作得很好,但我遇到的一個反覆出現的問題是它似乎截斷了一些字符串。以下是錯誤輸出之一:爲什麼我的腳本似乎隨機截斷字符串?
錯誤號:-2147217900描述:[微軟] [ODBC SQL服務器 程序] [SQL小號erver]閉合的引號的字符串後 「STRINGSEGMENT ^甕:UUID :e9 e91fe151-5w4c-12e1-bac5-25b3a0'。
INSERT INTO TableName VALUES('23189','23189','','','1 ^^','','12/5/2013 3:37:2 2 PM','fieldvalue '','somethinghere','somethinghere','2013年12月5日上午9:37:22 AM','123456','1234568798','STRINGSEGMENT^urn:uuid: e91fe151-5w4c-12e1- bac5-25b3a0
查詢長
如果你看一下源數據584個字符,被截斷的字符串看起來是這樣的:
STRINGSEGMENT ^甕:UUID:e91fe151-5w4c-12e1上,bac5-25b3a 004b00^STRINGSEGMENT
所以它切斷它從第53字符後(高亮)。 tSQL
的整個長度只有584個字符。
這是怎麼發生的?
WScript.Echo "Setting Vars..."
Dim sConnect, tConnect, resultSet, r
Dim sDSN, sUserName, sPassWord
Dim tDSN, tUserName, tPassWord
Dim value
sDSN = "mydsn"
sUsername = "myusername"
sPassword = "mypassword"
tDSN = "LOCAL"
tUsername = "myusername"
tPassword = "mypassword"
sTable = "sourceTable"
tTable = "targetTable"
sSQL = "" 'see below
sDSN = "DSN=" & sDSN & ";UID=" & sUsername & ";PWD=" & sPassword & ";"
tSQL = "Select TOP 1 ID FROM " & tTable & " ORDER BY ID Desc"
tDSN = "DSN=" & tDSN & ";UID=" & sUsername & ";PWD=" & sPassword & ";"
Set sConnect = CreateObject("ADODB.Connection")
WScript.Echo "Opening connection to source..."
sConnect.Open sDSN
Set tConnect = CreateObject("ADODB.Connection")
WScript.Echo "Opening connection to target..."
tConnect.Open tDSN
WScript.Echo "Finding Current Record..."
Set r = tConnect.Execute(tSQL)
On Error Resume Next
r.MoveFirst
if r.eof Then currentRecord = 1
Err.Clear
Do While Not r.eof
currentRecord = r("ID") + 1
r.MoveNext
Loop
r.Close
sSQL ="Select * FROM " & sTable & " WHERE ID >= " & currentRecord
WScript.Echo "Beginning shadow at record " & currentRecord & "..."
Set resultSet = sConnect.Execute(sSQL)
resultSet.MoveFirst
Do While Not resultSet.eof
On Error Resume Next
tSQL = "INSERT INTO " & tTable & " VALUES ('"
For i = 0 To resultSet.fields.Count - 1
if NOT IsNull(resultSet(i)) Then
value = replace(resultSet(i),"'","")
'somewhere around here
else
value = ""
End If
tSQL = tSQL & value
if i < resultSet.fields.Count - 1 Then
tSQL = tSQL & "','"
end if
Next
tSQL = tSQL & "')"
'when the error occurs, the line above doesn't seem to be processed but the line below obviously is...
tConnect.Execute(tSQL)
If (Err.Number <> 0) Then
WScript.Echo "Error Number: " & Err.Number & " Description: " & Err.Description
WScript.Echo tSQL
WScript.Echo "Query is " & Len(tSQL) & " characters long"
WScript.StdIn.ReadLine
Err.Clear
End If
tSQL = ""
resultSet.MoveNext
Loop
resultSet.Close
sConnect.Close
Set sConnect = Nothing
tConnect.Close
Set tConnect = Nothing
WScript.Quit(0)
它在'...- 25b3a0' ** 00 **'4b00^STRINGSEGMENT'中是'00'。我認爲一個'0x00'值被認爲是字符串終結符的字節......(我不知道'STRINGSEGMENT'的含義和它來自哪裏)... – JosefZ
關於如何避免這種情況的任何想法? –
STRINGSEGMENT也是我用來替換私有文本的文本。 :)我不認爲它在這個問題上有任何相關性。 –