Tuesday, February 21, 2012

SQLActiveScriptHost Example

SQLActiveScriptHost.Print "Hello World"

Dim conn, rs
Dim sql, sProvider, sCString

''sProvider = "Microsoft.JET.OLEDB.4.0"
sProvider = "Microsoft.ACE.OLEDB.12.0"
sCString = "Data Source= c:\temp\tryme.mdb"

sql = "SELECT * FROM tryme;"

Set conn = SQLActiveScriptHost.CreateObject("ADODB.Connection")
With conn
.Provider = sProvider
.Mode = adModeRead
.ConnectionString = sCString
.Open
End With

SQLActiveScriptHost.Print "Connected..."

Set rs = conn.Execute(sql)

While Not rs.EOF
rs.MoveNext
WEnd

SQLActiveScriptHost.Print "Executed SQL..."

conn.Close
Set conn = Nothing

SQLActiveScriptHost.Print "Connection Closed."


Note: SQLActiveScriptHost is being deprecated in a future version of SQL Server (Post 2008 R2)

No comments:

Post a Comment