简体   繁体   中英

VBScript SQL Bulk Insert Statement

I have a simple sql bulk insert statement that works well inside sql mgmt studios. I'm trying to run the sql command from a .vbs file. Here is my vbscript code. It makes it all the way to the msgbox and displays the message. It doesn't show any errors so it appears to be completing, but the table is blank in the db so no data was imported. What am I missing?

option explicit

Dim objConn
Dim objRS
Dim strSQL
Dim ConnectionString

Dim fso             
Dim objArgs

ConnectionString = "Provider=SQLOLEDB;Server=mtgops047-db006;Database=interlinqe3;Trusted_Connection=yes"

Set objConn = CreateObject ("ADODB.Connection")
Set objRS = CreateObject ("ADODB.RecordSet")
Set fso = CreateObject("Scripting.FileSystemObject")

objConn.Open ConnectionString

strSQL = "delete from Settlement_Import_Data"
strSQL = strSQL & " BULK INSERT Settle_Import_Data"
strSQL = strSQL & " FROM '\\server\sharedfolder\importdata.txt' with"
strSQL = strSQL & " ( FIELDTERMINATOR =',', ROWTERMINATOR = '\n')"


Set objRS = Nothing
objConn.Close
Set objConn = Nothing
MsgBox ("Update Complete!") 
WScript.Quit()

objConn.Execute() once for your delete statement and call it again for your bulk insert statement solved the issue. Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM