santhosh.yamsani has asked for the wisdom of the Perl Monks concerning the following question:

Thanks for your reply

I am working on SQL SERVER 2008.

Previously i had created Data Source name.With the help of DSN i had connected to data base.But now i donot have any DSNs but i have Server name and data base name.

Is there any possibility to connect to database with only above parameters.

Thanks in advance..

Replies are listed 'Best First'.
Re: Connection to DataBase
by marto (Cardinal) on Sep 14, 2010 at 10:09 UTC

    Have you looked at the DBI module? Your previous question suggests that you know how to connect to databases. The documentation shows how to use the connect method to connect to remote hosts.

    Update: Also, please read How do I post a question effectively? as you fail to mention which database product you're working with.

Re: Connection to DataBase
by nikosv (Deacon) on Sep 14, 2010 at 18:05 UTC

    From the DSN part of your question I gather that you've been using ODBC and you had to set the DNS up.

    With DBI you do not have to do that.Just use the server name straight up(if you have made the correlation to it's ip address inside the client's host file,so it is able to look it up)and the database name

    As marto suggests look up the DBI docs.

      In this particular case the docs of DBD::ODBC will be more instructive.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

      You can use DBD::ADO or DBD::ODBC to connect to SQL Server 2008 databases, if you use DBD::ODBC you may google for "DSN less connection", this is what you need. Using BDB::ADO the connection should look like:

      my $userid = q{}; my $password = q{}; my $strCnn = "Provider=SQLOLEDB; Data Source=$Servername; Initial +Catalog=$Tablename; Integrated Security=SSPI;"; $dbh = DBI->connect( "dbi:ADO:$strCnn", $userid, $password, { Rais +eError => 1, AutoCommit => 0 } ) or croak "Cannot connect: $DBI::errstr";

      but beware, there is a problem: SQLOLEDB may truncate inserted strings. Look at the docs of DBD::ADO.

      If you use DBD::ODBC the connection should look like:

      my $data_source = qq/dbi:ODBC:driver={SQL Server};Server=$Serverna +me;database=$DataBaseName;Regional=No;/; my $user = q//; my $password = q//; $dbh = DBI->connect($data_source, $user, $password) or die "Can't connect to $data_source: $DBI::errstr";

      Hope that helps.

Re: Connection to DataBase
by Anonymous Monk on Sep 14, 2010 at 10:08 UTC
    Is there any possibility to connect to database with only above parameters.

    It depends entirely upon the database