Advertisement
Advertisement
| 09.03.2008 at 08:11AM PDT, ID: 23699528 | Points: 125 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: |
Option explicit
'On Error Resume Next
'---- DataTypeEnum Values ----
Const adEmpty = 0
Const adTinyInt = 16
Const adSmallInt = 2
Const adInteger = 3
Const adBigInt = 20
Const adUnsignedTinyInt = 17
Const adUnsignedSmallInt = 18
Const adUnsignedInt = 19
Const adUnsignedBigInt = 21
Const adSingle = 4
Const adDouble = 5
Const adCurrency = 6
Const adDecimal = 14
Const adNumeric = 131
Const adBoolean = 11
Const adError = 10
Const adUserDefined = 132
Const adVariant = 12
Const adIDispatch = 9
Const adIUnknown = 13
Const adGUID = 72
Const adDate = 7
Const adDBDate = 133
Const adDBTime = 134
Const adDBTimeStamp = 135
Const adBSTR = 8
Const adChar = 129
Const adVarChar = 200
Const adLongVarChar = 201
Const adWChar = 130
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adBinary = 128
Const adVarBinary = 204
Const adLongVarBinary = 205
Const adChapter = 136
Const adFileTime = 64
Const adDBFileTime = 137
Const adPropVariant = 138
Const adVarNumeric = 139
Const adTypeText = 2
Const adTypeBinary = 1
'---- CommandTypeEnum Values ----
Const adCmdText = &H0001
Const adCmdStoredProc = &H0004
'---- ParameterDirectionEnum Values ----
Const adParamInput = &H0001
Const adParamOutput = &H0002
'---- SaveOptionsEnum Values ----
Const adSaveCreateNotExist = 1
Const adSaveCreateOverWrite = 2
Dim fso, outFile, fs
Dim conn
Dim rs
Dim objArgs
Dim queryStr
Dim oerr
WScript.Echo "BLOB extractor using SQL Server Provider for OLE-DB"
Set objArgs = WScript.Arguments
If (objArgs.Count <> 4) Then
WScript.Echo "Syntax:"
WScript.Echo " CScript.exe SampleBlobExtractor.vbs <database> <server> <userid> <password>"
WScript.Echo
WScript.Echo "Note:"
WScript.Echo " Windows Integrated Security (Trusted Connection) will be used"
WScript.Echo " if the <userid> and <password> params are empty strings."
WScript.Quit
End If
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "sqloledb"
conn.Properties("Data Source").Value = objArgs(1)
If objArgs(2) = "" Then
conn.Properties("Integrated Security").Value = "SSPI"
Else
conn.Properties("User ID").Value = objArgs(2)
conn.Properties("Password").Value = objArgs(3)
End If
conn.Properties("Initial Catalog").Value = objArgs(0)
conn.Open
Set rs = CreateObject("ADODB.Recordset")
queryStr = "SELECT CAST(SERVERPROPERTY('MachineName') AS VARCHAR(30)) + '\' + CAST(ISNULL(SERVERPROPERTY('InstanceName'), '') AS VARCHAR(30)), CURRENT_USER"
rs.Open queryStr, conn
WScript.Echo "Successful connection to SQL Server instance [" & rs(0) & "] as user [" & rs(1) & "]"
rs.Close
Set rs = Nothing
' Output file
Set fso = CreateObject("Scripting.FileSystemObject")
Set fs = CreateObject("ADODB.Stream")
fs.Type = adTypeBinary
Set rs = CreateObject("ADODB.Recordset")
queryStr = "SELECT QUOTENUMBER, EMBEDDEDOBJECT from quotes where quotenumber='070464'"
rs.Open queryStr, conn
Do Until rs.EOF
outFile = rs(0) & "." & "PDF"
WScript.Echo "Extracting " & outFile
fs.Open
fs.Write rs(1)
fs.SaveToFile outFile, adSaveCreateOverWrite
fs.Close
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Set fs = Nothing
Set fso = Nothing
|