in reply to Re: Database connection issue
in thread Database connection issue

I double checked the ODBC and it is spelled correctly. The source itself says that it's on both 32-bit and 64-bit platforms, so I don't think that's the issue. Could be, but I don' think so. I checked the link you helpfully provided but it nets me with another error altogether. The code would look like this,

my $dbh = DBI -> connect("Driver={SqlServer};SERVER=CND4290H26;Databa +se=GameInfo;Trusted_Connection=Yes;") or die "Couldn't open database";

That gives me the error: Can't connect to data source because I can't work out what driver to use (It doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set) at script.pl line 11. When I put back the DBI:Driver, I get the same error I initially posted.

Replies are listed 'Best First'.
Re^3: Database connection issue
by Corion (Patriarch) on Nov 15, 2015 at 07:53 UTC

    That's expected. You will need to combine your reading of DBI together with the information from connectionstrings.com. You will need to add the correct DBD information in front of the connection string:

    my $dsn = "dbi:ODBC:Driver={SqlServer};SERVER=CND4290H26;Database=Game +Info;Trusted_Connection=Yes;"; my $dbh = DBI->connect( $dsn ) or die ...;

      Apologies for the delay, but I was too busy yesterday to respond. I can gleefully admit that the code you provided definitely got me a bit further along, but the error message ever remains the same. The only difference this time is that the "Or die" message included is showing up, but maybe not how I think it should? If that's even a thing.

      my $dsn = "dbi:ODBC:Driver={SqlServer};SERVER=CND4290H26;Database=Gam +eInfo; Trusted_Connection=Yes;"; my $dbh = DBI->connect($dsn) or die "Couldn't connect.";

      As you can see I did modify the code thanks to your inclusion, but the error message is remaining the same. The only inclusion to that, since I ran in debug mode, is: "Uncaught exception from user code: Couldn't connect. at script.pl line 12." That is the connect or die dbh that attempts to call the dsn to connect. The error has to be somewhere in the dsn. Since I'm trying to call it locally, could the error be in the server? Or is it perhaps still an issue with the driver? I apologize for not really getting it, I'm a newcomer with perl.

        To get more information from DBI, use the ->connect call as it is documented in DBI:

        $dbh = DBI->connect($data_source, $username, $password) or die $DBI::errstr;

        This should output a bit more information.