Hi, I'm new here. I get this message in the {wx_dir}/samples/db sample:
------------------------------------------------ DB CONNECTION ERROR...
Unable to connect to the data source.
Check the name of your data source to verify it has been correctly entered/spelled.
With some databases, the user name and password must be created with full rights to the CONTACT table prior to making a connection (using tools provided by the database manufacturer) ------------------------------------------------
My problem is: I cannot connect to any ODBC database (the sample can be compiled with no errors and run). I also tried my own code (similar to one example):
DbConnectInfo = new wxDbConnectInf(NULL, "any DSN", "", ""); if (!DbConnectInfo || !DbConnectInfo->GetHenv()) return HandleError("Unable to allocate an ODBC environment handle");
db = wxDbGetConnection(DbConnectInfo); if (!db) return HandleError("Cannot connect to the database"); ------------------------------------------------
wxDbGetConnection() returns 0 (tested databases doesn't require login and password). I don't know what I should do and I need working with databases. If it fails I will have to use another library, but I like wxWidgets :(
2. Re: Unable to connect to the data source
#4524
Posted by: 2004-06-18 03:59:11
I've tried code from upCASE's answer in the "wxWindows odbc" thread and it works fine! I've replaced:
------------------------------------------------ db = wxDbGetConnection(DbConnectInfo); if (!db) return HandleError("Cannot connect to the database"); ------------------------------------------------
with:
------------------------------------------------ db = new wxDb(DbConnectInfo->GetHenv()); db->Open(DbConnectInfo);
if(!db->IsOpen()) return HandleError("Cannot connect to the database"); ------------------------------------------------
and now I can e.g. "db->ExecSql("UPDATE KMOD SET A31 = -A31"); db->CommitTrans();" and see the changes! Thank you upCASE! Maybe it is something wrong in wxDbGetConnection()...