Solved

ODBC in VBScript

Posted on 2001-07-18
8
834 Views
Last Modified: 2006-11-17
My database(MS Access) reside on a different PC,
I can't establish the connection my PC and the PC which has my database.

I already used the ODBC with the "data source system"

Set strConn = Server.CreateObject ("ADODB.Connection")
strnConn.Open "data source=dsntestdb;user id=Admin;pwd=my_password"

But if the data source (dsntestdb) points to the MS Access file on the same PC, this code is very good.

I'd like to know how can we give the user id and password for connecting to the distant PC ?

Is my code is good ?
0
Comment
Question by:longlong
8 Comments
 
LVL 20

Expert Comment

by:hes
ID: 6294186
In the control panel go into ODBC data sources 32bit
and create a system DSN pointing to the remote database

then for your "data source"= use the name of the system dsn you created
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6294188
When you say distant, how distant. If it is on a lan, you should be able to specify the UNC path to the database:

\\ServerName\ShareName\FolderName\DatabaseName.mdb in the dsn definition.
0
 

Author Comment

by:longlong
ID: 6294342
But I have to use the system data source or the file data source ? What is the difference ?
I used the system data source but it appeared the error message, you don't have the autorisation for accessing.
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6294356
This can be done by selecting a database on the network

Just click on the network button and select the Machine,  folder and database required.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6294426
BTW through ODBC you cannot use an UNC path to the file.

ODBC will map a drive for you.

You also must have asscess to the in which folder the database resides.

Go to the Machine and open explorer right click on the folder select sharing, Share As Name of folder.

Alternatively you could use a DSNless connection.

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;data source=\\Test\Temp\Anydb.mdb;user id=Admin;pwd=my_password"

This will work with an UNC and without the need for a DSN.

The Data Source= bit should be the UNC path to your database on the network.

Vin.

0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6294543
I wouldn't recommend using a DSN-Less connection in VBScript... it would expose your UID and PWD to everyone.

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;data source=\\Test\Temp\Anydb.mdb;user id=Admin;pwd=my_password"

If you build your DSN and hit the advanced button you can build the DSN with a User Id and password!
0
 

Author Comment

by:longlong
ID: 6307492
I'd like to know the password which we gave, this is the password for network (login to another PC on the network) or this is the file's password (password for open this file).

If I want to give the password for login to another PC bacause my database (Aceess) is on another PC, how can I do it ?
Thank.
0
 
LVL 4

Accepted Solution

by:
VincentLawlor earned 300 total points
ID: 6307613
The password supplied to the connectio string is the password for the database.

As I said in an earlier post you will need access to the machine on which the Access database resides.

* Go to the machine on which it resides and share the folder. You will then be able to access the database from another machine.
Then:
* Map a network drive from the machine that needs to access the database. You will be asked for a username and password (Network username and password). Setup your ODBC connection as normal.
Or:
* In ODBC when you are selecting the database click the network button select the network share where the database resides (ODBC will map the drive for you). Enter the username and password (Network username and password).

If the database is password protected then in ODBC select Advanced settings and enter the username and password (Database username and password).

Hope this clears is tup for you.

Vin.

 
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now