Andreschrosa

Opening ODBC database

Recommended Posts

When trying to open ODBC database from scripting, I run in the following error:

O1002 Unable to open ODBC database: lookup Line 14 - Uncaught error in sequence lookup

global string DSN
global string user
global string passw
private handle
private result

DSN = 'DSLeituras'
user = 'root'
passw = ''
handle = db.open(DSN, user, passw) ///this is line 14///

anything wrong with this declaration? :rolleyes:

Share this post


Link to post
Share on other sites

Possibly. First, did you create an ODBC data source for your database, or is DSLeituras the actual name of the database? DAQFactory does not connect directly to databases, but rather uses ODBC as a linkage. You therefore have to create an ODBC data source. The user / password combination is usually for the ODBC linkage and not the database itself. You usually specify the database user/password when setting up the ODBC.

Share this post


Link to post
Share on other sites

Yes, I did crate the datasource using mysql.

I'm running windows vista 32 bits by the way.

Tried using:

handle = db.OpenEx("DSN ='DSLeituras'; UID ='root';PWD=;DATABASE ='leituras'")

then it returns the following error:

O1002 Unable to open ODBC database: lookup Line 14 - Uncaught error in sequence lookup

Share this post


Link to post
Share on other sites

You can't create the datasource in mySql. DataSources are an ODBC thing which is a windows thing, not a mysql thing. You will need to get the MySQL ODBC connector which is available from their website, install it, then create a datasource with it from windows ODBC settings (under administrator settings / ODBC). It is described in our help in general terms in the logging chapter.

Share this post


Link to post
Share on other sites

I did it, created the datasource in ODBC administrator in windows. I meant mysql as the base for the datasource.

Somehow it dosent seen to work. However, I can log data to this datasource using the logging component from DAQFactory.

Share this post


Link to post
Share on other sites

OK, in the logging set you are presumably not specifying a user name, right? So try opening it without using a user name. If that doesn't work, try creating a blank document and then open it from there. Its possible that the logging set is interfering with the db.open command.

Share this post


Link to post
Share on other sites

No good yet... tried opening a new document in DAQFactory and pasting the code there, it still dosent work.

I'm guessing it could have something to do with regional settings or somesuch, tried using "" and '' for the strings, but still no good.

Are those parameters from DAQFactory? DSN, UID, PWD, DATABASE? Or those should be particular to the mysql sql script?

global handle
handle = DB.OpenEx('DSN=dsleituras;UID=;PWD=;DATABASE=leituras')

Share this post


Link to post
Share on other sites

When you use OpenEx(), the string you specify is passed directly to ODBC, so the parameters are ODBC not DAQFactory. This is to allow complete control over the open string. I believe in the logging set (which uses a different technique to open databases than the db.openex() function) it opens with the string: "DSN=mydsn; ODBC;" where mydsn is the datasource string you specified in the logging set. Perhaps you just need the ODBC; at the end?

Share this post


Link to post
Share on other sites

Hmm, it shouldn't be this difficult. Maybe you have something mis-set in your ODBC settings. Can you post some screenshots of the ODBC settings?

Share this post


Link to post
Share on other sites

Sure, but as I said, this works with logging set.

After some searching on mysql developer network, I found some parameter to connect to the datasource, however, this also dosent work.

handle = DB.OpenEx("DSN='SLeituras'ODBC;DRIVER='{MySQL ODBC 5.1 Driver}';SERVER='localhost';DATABASE='leituras';UID='';PWD='';OPTION='3'")

screenshot of the ODBC configuration:

ODBC.jpg

Share this post


Link to post
Share on other sites

Note you have two typos in that last script, the DSN is wrong and you forgot the ; before ODBC.

Try these:

1) Open using Open() instead of OpenEx(). Unless you specified a user/password in the details of ODBC (not the "root" you specified), you should pass "" for user and password.

2) User this string:

handle = DB.OpenEx("DSN='DSLeituras'; UID=''; PWD=''; ODBC;)

Much of that extra stuff you specified in that last post does nothing because its in the ODBC driver.

Share this post


Link to post
Share on other sites

Still cant open it, should I call anything else before calling the db.open command? Maybe it's a issue with mysql and windows vista, maybe I should switch to another sql server and give it a try.

Share this post


Link to post
Share on other sites

I have the exact problem right now. db is working if using logging. But I cannot open it via script. The error is either cannot open or unknown error. I actually have tried all what you have tried before finding this post. I would like to ask how the issue is solved?

database name: ewsdb

odbc connector name: ews_data

odbc driver: mysql odbc 5.1 driver

Thanks.

Share this post


Link to post
Share on other sites

Not sure. It was, I believe, a syntax error, but Andreschrosa never replied saying it worked. Note that in this line:

handle = DB.OpenEx("DSN='DSLeituras'; UID=''; PWD=''; ODBC;")

the '' after UID and PWD are two single quotes ' and ', not a single double quote "

For you, the database name and type don't matter. Only the data source name: ews_data

I believe someone else had a problem where they created a datasource as a system DSN but it needed to be a user DSN. Its a recent post if I remember, probably under logging.

Share this post


Link to post
Share on other sites

I believe that it is kinda like a bug in daqfactory. The following is what I have now:

Using MySQL ODBC Connector 3.51:

db.Open("ews_data") : Working

Logging method: Working

Using MySQL ODBC Connector 5.1:

db.Open("ews_data"): O1003 Unknown error accessing ODBC database

Logging method: Working

So please verify which and what is wrong. It is definitely not some grammar issue at the user's side.

post-822-1236047716_thumb.jpg

Share this post


Link to post
Share on other sites

Nope, not a bug. DAQFactory simply calls the Windows API for ODBC, and certainly the fact it works in the logging set means DAQFactory is fine. The issue is your connection string. Obviously there is some difference in it that is making it not work. I believe the logging set adds "ODBC;" to the end of the connection string, so maybe that is it.

Share this post


Link to post
Share on other sites

Hi,

I am also facing same problem. I can open the ODBC database in logging & exporting. But, when I try to open it from sequence using both db.open and db.openEx methods, I am getting

"O1002 Unable to open ODBC database: s1 Line 5 - Uncaught error in sequence s1"

Please let me know how to resolve this issue?

Thank you

Share this post


Link to post
Share on other sites

dbase = db.Open("janitza")

this is my connection code to "Mysql Connector 5.1".. It works fine . and i defined user =root and a password for it. this statemnet needs too much experiment i think. i was uninstall the database server and the connector driver to solve that connection problems. But i can say Mysql connector doesn't need "OpenEx" function. you can write user and password on connectors interface..

Share this post


Link to post
Share on other sites

Yes, you can, but then anyone can connect to that ODBC connection. By requiring the password (not specifying it in the MySQL ODBC Connector, anyone connecting to it must provide a user/password. This adds a level of security.

Share this post


Link to post
Share on other sites

I had this problem too. Did you find the solution?

handle = DB.OpenEx("DSN='mysqldb'; UID=''; PWD=''; ODBC;")  I get the following error.

O1002 Unable to open ODBC database: Startup Line 16 - Uncaught error in sequence Startup
 

Share this post


Link to post
Share on other sites

I'm not sure.  That post was from 6 years ago.  If you don't need a user / password, I would just use db.open().  If that doesn't work, there are several possibilities, but the most likely one is:

DAQFactory is a 32 bit application, so you have create your ODBC data sources in the 32 bit version of ODBC.  On 64 bit versions of windows there are actually two ODBC control panels, one for 32 bit, and one for 64.  Unfortunately, only the 64 bit version shows in control panel.  Personally, I added a shortcut to the 32 bit version to my control panel.  The path on my computer is:

C:\Windows\SysWOW64\ODBCCP32.CPL

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now