Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting To SQL Via VBS

Status
Not open for further replies.

agent0047

Programmer
Jan 11, 2008
15
Thanks in advance, I am new to VBS and sp's so I am not really sure how to make this happen but here goes. I need a set of records that are grouped by 'Pending' to be updated every night via VBS, but I am not sure how to connect to the SQL Database with vbs. Any direction would be great?

set rs = Server.CreateObject ("ADODB.Recordset")
Set conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionString = "Provider=SQLNCLI;Server=SERVER\SQLEXPRESS;Database=Data;Trusted_Connection=yes;"
Conn.Open


sql = "SELECT * FROM [Data] WHERE [Data].[Status]="Pending"' " <--this should be grouped by 'Pending' so it chages all the pending records

rs.open sql, conn
'--

rs.Status="Processed"

rs.Update
rs.close
Conn.Close
 
There is nothing on there about vb only vb.net I don't need that but thanks for the reply
 
Connection Strings are specific to the data provider type, not the programming language you're using.

Its' been a while since I did any VBScript but I think you can use either the standard OLEDB or ODBC strings

[small]----signature below----[/small]
I'm pushing an elephant up the stairs

My Crummy Web Page
 
agent0047 said:
There is nothing on there about vb only vb.net I don't need that but thanks for the reply
That's not correct, look under the section SQL Native Client OLE DB Provider. ADO is what you use in VB, and ADO is a wrapper for OLE DB.

In any case your connection string looks correct, but you are using trusted security, which means whatever account the VBScript is running under needs to be a login with sufficient rights in SQL Server.

Besides, your update won't work because you can't update a field in a grouped SELECT statement.

Why use a recordset in any case? Just execute an update directly:

Conn.Execute "UPDATE [DATA] SET Status = 'Processed' WHERE Status = 'Pending'"


 
Ok I see now, but can you tell me if you guys think using the trusted rather than a password has security issues or not. The vbs is on the server but not in a root directory and runs locally. I read this could be a security issue but I don't see how as long as the server it’s on is secured from outside intrusion but I want to make sure I am not missing something. Thanks all for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top