Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Unable to connect to the data source

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Unable to connect to the data source
#4523
Posted by: 2004-06-18 03:29:43
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)
------------------------------------------------

I use "Dev-C++ 4.9.8.10" + "g++ (GCC) 3.3.1 (mingw special 20030804-1)" + "wxMSW-2.4.2.zip" compiled according to <http://www.upcase.de/devpack.html> (with ODBC support, without Unicode, FINAL=1). I tried <http://www.upcase.de/stuff/wxWidgets251.DevPak>, too.

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):

------------------------------------------------
wxDbConnectInf *DbConnectInfo = NULL;
wxDb *db = NULL;

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 :(
Message2. 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()...

Ladis
see my game at <http://zimtech.ceskehry.cz> :)
Message3. Re: Unable to connect to the data source
#4528
Posted by: upCASE 2004-06-18 14:59:29
Hi!
Glad it works now :)
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥1,390.00 ·
 
 
¥287.00 ·
 
 
¥410.00 ·
 
 
¥1,380.00 ·
 
 
¥1,080.00 ·
 
 
¥271.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0