3

We have a perl script on a Linux machine that connects to the SQL Server database and fetches information, we are trying to update the database host details but could not find parameter or variable that that does this in that script.

use strict;
use XML::Simple;
use Data::Dumper;
use DBI;
use DBI qw(:sql_types);
use MIME::lite;
my $SQL_Datasource= 'dbi:ODBC:eventMSSQL';
my $SQL_user= 'user1';
my $SQL_password ='abc@123';
$dbh=DBI->connect($SQL_Datasourse,$SQL_user,$SQL_password)

2 Answers 2

2

Your script is connecting to a database defined under the data source name (DSN) eventMSSQL.

To change the host you connect to, you have three options.

First, you could modify this DSN definition to point to a different host. This eventMSSQL DSN is defined somewhere in your Linux system's ODBC installation, probably in /etc/odbc.ini or ~/.odbc.ini.

Alternatively, you could create a new DSN definition with a different host, and connect to that instead.

Finally, you could also change your DBI->connect data_source to include an ODBC connection string instead of a DSN, which would look something like dbi:ODBC:Driver=...;Host=...;Port=.... (The DSN is a shorthand for that Driver/Host/Port/etc. specification.)

The DBD::ODBC::FAQ has an entry on DSNs and connection strings which is illuminating here.

Sign up to request clarification or add additional context in comments.

Comments

1

Some ODBC drivers store the connection information in some dedicated files .

as a example UnixODBC store in a file named odbcinst.ini in /etc

source ( https://www.easysoft.com/developer/languages/perl/dbd_odbc_tutorial_part_1.html )

2 Comments

Hi Mike, in the osbcinst.ini I did see a Sql Server configuration, However I could not find parameter that holds host details.
I believe odbcinst.ini defines available ODBC drivers, not databases. It answers the question, where can the ODBC installation find Firebird or PostgreSQL or SQL Server or Oracle or etc. drivers? DSNs are specified elsewhere, referencing those driver definitions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.