ADS

Featured

Connect to MS Access Database Driver and Others in VBS Scripts


Here is the connection string, which we often need to find on the internet and not easily found.

You can create programs based on the Visual Basic Runtime language (* .vbs), even without having a program for creating programs.

Create a new db.mdb file, and create a * .vbs file with the following lines:






Set db = CreateObject("ADODB.Connection")
Set recordset = CreateObject("ADODB.Recordset")
db.Open = "DRIVER=Driver do Microsoft Access (*.mdb);DBQ=db.mdb;" // Driver e DB
recordset.Open "create table dados (cod int,nome text,endereco text,cod2 text,telefone text)",db
db.Close

I colored it to make it easier to understand the code, and its variables. The light green part is the SQL code, which can be whatever you want. This is basically to create a VBS file.
To create a page in ASP, just change the "CreateObject (*)", placing "Server.CreateObject (*)", because to create an object, it must be created in the user's session, however there is no way to use it in this way. VBS files, but the connection string is the same.

There are other connection drivers, such as:
DRIVER=Microsoft Access Driver (*.mdb)
DRIVER=Microsoft Excel Driver (*.xls)
DRIVER=Microsoft dBase Driver (*.dbf)

Both "Microsoft Access Driver (* .mdb)" and "Microsoft Access Driver (* .mdb)" can be used, as there is a language difference, which is detectable by the driver, but it is recommended to use the international standard, since that not all systems can have the driver for the Portuguese standard.

There are others, which you may need to install beforehand to run:
DRIVER=Microsoft Paradox Driver (*.db)
DRIVER=Microsoft Paradox-Treiber (*.db)
DRIVER=Microsoft Text Driver (*.txt; *.csv)
DRIVER=Microsoft Text-Treiber (*.txt; *.csv)

It can also be written like this:
DRIVER={Microsoft Access Driver (*.mdb)}

It is very important to inform that the keys are optional, however, the parentheses with the name of the extension, is part of the name of the driver, and cannot be discarded, that is, it is part of the connection call to the database.

Take note: The expressions DBQ, UID, PWD, refer to the Microsoft Access driver, and can change according to the selected driver, for example, SQL Server needs "SERVER" instead of "DBQ".

No comments