If you are using SQLServer than I do not think 'selectdb()' is going to work for you. You are either using DBD::ODBC or DBD::ADO neither of which have selectdb in them which one is it??

If there is a way with ADO to get a list of all the tables in a DB but I don't remember. I think you have to use DMO or even SMO to get that kind of information and that is well out of the scope of DBI/DBD

Are you using SQL server 05 or 08 or something older?

Cheers
John





Hi,
As Alex asked me why I not giving the name of the database in the connection string, the script I writing is basically a testing scripting.It will connect to the database engine then iterate over all the database available.If the database of my interest is available I will connect to it.Else I will thrown an error. Simple solution what I thought is giving the database name in connection string.If the connection is not successful, then it is clear the database is not there.But What if there is ten or fifteen db I have to check for.I dont want to hardcode for all the database.I want to have a generalised solution.

John, the code provided by you is for Mysql.I actually struck with sql server.When I slightly modified your code for sql server.I got the same error "selectdb()" cannot be found.

    Please help me with this.

Thanks & Regards,
Manikandan.G
On Fri, May 14, 2010 at 8:50 PM, John Scoles <sco...@pythian.com <mailto:sco...@pythian.com>> wrote:

    Alexander Foken wrote:

        On 13.05.2010 16:58, mani kandan wrote:

            Hi Tim,

             I wrote a small script that connect to SQL Server
            engine.I don't want to
            give the name of the databse in the connection string.

        Why not?
            I want to select a db
            on the fly only if it present.

        When WHAT is present?

            I tried $dbh->selectdb($databasename) but this
            failed throwing error can't able to locate object method
            "selectdb" in
            package dbi::db.


    I think the selectdb is part of the Mysql  demo mod

    haven't  used it in years but here is a quick use of it

    #!/usr/bin/perl
    # PERL MODULE
    use Mysql;
    # MYSQL CONFIG VARIABLES
    $host = "localhost";
    $database = "store";
    $tablename = "inventory";
    $user = "username";
    $pw = "password";
    # PERL CONNECT()
    $connect = Mysql->connect($host, $database, $user, $pw);
    # SELECT DB
    $connect->selectdb($database);


    Mysql I think is a nice wrapper for DBD::mysql but don't quote me
    on that;)

    cheers
    John Scoles


        There is no such method in DBI, and as far as I know, there
        was never one.

        The only way to specify a database is to use the connect()
        method of the DBI class.

            Please help me on this.I work with microsoft sql server
            2005.
        What DBD do you use? DBD::ODBC?

        Alexander







Reply via email to