larwilliams has asked for the wisdom of the Perl Monks concerning the following question:

Hello :)

I am attempting to connect to a MS SQL Server using DBD::ADO and i was wondering how to include the "DefaultDatabase" attribute in the connect string. The DSN i'm using doesn't have a default database set, so i must use the "DefaultDatabase" attribute.

Please provide a code sample :) Here's the code i'm trying to use, but i get a "permission denied for master database" error

$corantosql_dbh = DBI->connect("DBI:$CConfig{'CorantoSQL_dbserver'}:$CConfig{'CorantoSQL_dbhost'};DefaultDatabase=$CConfig{'CorantoSQL_dbname'}","$CConfig{'CorantoSQL_dbuser'}","$CConfig{'CorantoSQL_dbpass'}");Thanks!

Replies are listed 'Best First'.
Re: DBD::ADO
by impossiblerobot (Deacon) on Mar 09, 2002 at 21:44 UTC
    A DBI data source starts with "dbi:" followed by the driver name. Everything after that (in the same string) is passed to the driver itself. So what you need is something like DBI->connect("dbi:ADO:$dsn", $user, $passwd) where $dsn is a valid ADO connection string.

    The DBD::ADO documentation references http://www.able-consulting.com/ADO_Conn.htm#DSN as a source of documentation on constructing ADO connection strings. There are several examples there.

    Note that I have never used DBD::ADO; all of this was gleaned from reading the documentation.

    Impossible Robot
      Thanks man... this could be a major help to me :)
Re: DBD::ADO
by larwilliams (Initiate) on Mar 09, 2002 at 19:04 UTC
    Just a little sidenote: Please don't suggest that i use DBD::ODBC instead, 'cause it's pointless. The company i'm working for won't give me telnet access to install it ( if i did, i would! ).

    Instead, all i got to work with is MS SQL Server, DBD::ADO, and a database.... so i have to make do, for now :)