VBscript to connect to sql server and run query
VBScript provides one of the best ways to connect to any kind of database. That is through the ADODB connection.
You just need to have the correct connection string with the right credentials. If you have these two then you can write code to connect to almost any kind of database in just 3 lines.
In order to connect to the database, we need to follow below steps:
- Create an object of ADODB, like below:
- Create an object of recordset :
- Open the Connection using the connection string
- Run the query using the connection object.
rs.open "select * from emp",con
This will store the data into the recordset object rs.
This page has all the code needed for connecting and reading data from popular database types using VBscript.