picasothakkar
asked on
Microsoft Text Driver for ODBC - Error while trying to retrieve information from the csv file
I have a ODBC wrapper class in my application which opens a connection using DSN username & password (user supplies this in the startup of application). Internally the application calls OpenConnection method to connect to dsn.
Ideally this works for most of the databases. However now i want to use a comma seperated file as a database. I created an ODBC using microsoft text driver. I try to give this DSN details to my application (essentially only the user name) although i don't get any error while connecting. I get the following error when my application executes a select statement (select * from table_name order by email_address):
[Microsoft][ODBC Text Driver] The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data.'
Ideally this works for most of the databases. However now i want to use a comma seperated file as a database. I created an ODBC using microsoft text driver. I try to give this DSN details to my application (essentially only the user name) although i don't get any error while connecting. I get the following error when my application executes a select statement (select * from table_name order by email_address):
[Microsoft][ODBC Text Driver] The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data.'
ASKER
the application is using the following method to establish the connection
odbc::Connection *
OdbcDirectory::OpenOdbcCon nection(
string &sErrMsg
)
{
sErrMsg = "";
LogFA(getLogID(), LOG_INFO,
"OdbcDirectory::OpenOdbcCo nnection() : dsn='%s', userid='%s'",
this->m_dsn.c_str(), this->m_userId.c_str());
try {
this->m_pSession = DriverManager::getConnecti on(this->m _dsn,
this->m_userId, this->m_password);
return this->m_pSession;
}
catch(SQLException& e) {
sErrMsg = "ODBC connection failed: " + e.getMessage();
LogFA(getLogID(), LOG_FATAL,
"OdbcDirectory::OpenOdbcCo nnection() : %s", sErrMsg.c_str());
return NULL;
}
}
odbc::Connection *
OdbcDirectory::OpenOdbcCon
string &sErrMsg
)
{
sErrMsg = "";
LogFA(getLogID(), LOG_INFO,
"OdbcDirectory::OpenOdbcCo
this->m_dsn.c_str(), this->m_userId.c_str());
try {
this->m_pSession = DriverManager::getConnecti
this->m_userId, this->m_password);
return this->m_pSession;
}
catch(SQLException& e) {
sErrMsg = "ODBC connection failed: " + e.getMessage();
LogFA(getLogID(), LOG_FATAL,
"OdbcDirectory::OpenOdbcCo
return NULL;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you have the latest Microsoft Jet database engine installed?
ASKER
i am sorry but i realized the mistake. The table name has to be same as file name. Also the table name should have extension. i.e. "select * from table_name.txt".
I am getting the results now after making the above changes.
I am getting the results now after making the above changes.
Please show us the conection string you're using.
David Maisonave :-)
Cheers!