vbscript连接到sql server运行查询将结果保存到csv

时间:2015-10-13 23:13:36

标签: sql-server vbscript

我正在尝试创建一个连接到sql server的脚本,选择一些数据,并将结果保存到csv。 Windows身份验证在Sql Server中启用。

这是我到目前为止所拥有的:

Dim connect, sql, resultSet, pth, txt

Set connect = CreateObject("ADODB.Connection")
connect.ConnectionString = "Provider=SQLOLEDB;Server=server\instance;Database=pm;Trusted_Connection=True;"
connect.Open

sql="SELECT col1, col2 FROM tbl1 order by col1, col2"

Set resultSet = connect.Execute(sql)

pth = "d:\test.csv"
Set txt = fs.CreateTextFile(pth, True)

On Error Resume Next
resultSet.MoveFirst
Do While Not resultSet.eof
  txt.WriteLine(resultSet(0) & "," & resultSet(1))
  resultSet.MoveNext
Loop

resultSet.Close
connect.Close
Set connect = Nothing

我收到错误:

d:\vbs_test.vbs(5, 1) Microsoft OLE DB Provider for SQL Server: Invalid authorization specification

0 个答案:

没有答案