Forum Moderators: coopster & phranque

Message Too Old, No Replies

Problem with DBI ODBC connection

         

DrDoc

8:01 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to connect to a database over the network, but I can't seem to get it to work.

Let's say that the name of the database is 'foobar', located in '\\server\path\to\db\'... What's my DBI->connect supposed to look like?

I've looked at the DBI docs... but I'm utterly confused :)

I got sent a document with the query and everything (they used to run it in Excel) and the connection part looks something like this:
DSN=foobar;Directory=L:\path\to\db;SERVER=NotTheServer

...if that helps :)

coopster

8:37 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's been awhile, but I believe you basically have two options when using the DBD::ODBC DBI interface:
  1. dbi:ODBC:odbc_dsn
  2. dbi:ODBC:driver= Microsoft Access Driver (*.mdb);dbq=\\server\path\to\db\access.mdb

where
odbc_dsn
is the ODBC Data Source Name (a name used to refer to a set of driver-specific connection parameters which are typically the ODBC driver to use, the database name, etc.).

It's much easier to use the MS ODBC32 wizard found in the Control Panel to setup the DSN and use rather than the second option which requires you to put together the entire connection string.

So, using the DSN information they gave you, your connection would be:


my $dbh = DBI->connect("dbi:ODBC:foobar")
or die "Cannot connect at this time: $DBI::errstr\n";

DrDoc

8:57 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is that I keep getting "connection failed" error messages all the time...
I don't know if it's related to the syntax or not.

DrDoc

9:08 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The database is a MAS90 (or, MAS200) db, if that makes a difference?

coopster

9:14 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Can you open a table in the database using a program (such as Access or Excel) on the computer you are using to make the connection via the ODBC DSN created on that machine?

DrDoc

7:20 pm on Dec 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Still no go...

Anyone who has worked with DBI::ODBC connections to MAS90 (SOTAMAS90) before?
I think I have it all figured out, except for which driver to use :(