Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database object not found error on msql

Status
Not open for further replies.

mikeprestim

Programmer
Mar 1, 2001
21
GB
Hi

I have installed MS SQL server on my pc and created DB called test. I have also created my table to it. When i try and query the table i get an invalid object name error refering to my table. I know my table is spelt correctly and i can see the table in Enterprise manager. If i change the table name to one of the default tables then all is ok.

Below is my code it is just stock stuff. Does any one have any ideas

use DBI;

use DBD::ODBC;

my $dbh = DBI->connect( "DBI:ODBC:test", "", "" ) or
die( "Could not make connection to database: $DBI::errstr" );

my $sth = $dbh->prepare( 'SELECT * FROM dtImp' ) or
die( "Cannot prepare statement: ", $dbh->errstr(), "\n" );

my $rc = $sth->execute() or
die( "Cannot execute statement: ", $sth->errstr(), "\n" );

my @array;

while ( @array = $sth->fetchrow_array() ) {
write();
}

# Check to see if fetch terminated early
warn( $DBI::errstr ) if $DBI::err;

$sth->finish();

$dbh->disconnect();

format STDOUT =
@<<<<<<@<<<<<<<<<
$array[ 0 ], $array[ 1 ]
.

 
You're running on Windows, yeah? I suspect you're going to need to register your database as a DSN (data source name). Should be under Admin Tools | Data Sources (ODBC).

Alternately, search on google for dsn less connections.
 
Thanks, forgot to put that one in. Yes i set up a DSN 1st. My code works fine for the default tables which were set up when the database called test was created. For example the table called sysusers diplays the 1st two columns to STDOUT
 
I have spent hours on this. got it sorted at last. In the prepare statement I needed to define the table name as database.owner.table as follows test.dbo.sImp then it all works ok.

i started to play with the SQL Query Analyser and started to get similar errors

Thanks anyway
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top