question

Ben K2 avatar image
1 Like"
Ben K2 asked Felix G2 commented

How to use ODBC in a correctly way?

Hey guys,

I have a problem with my database connection. I am using MySQL80.

Everything is working, when I am using the FlexSim DBConnector (picture 1). There is not any error meesage when I am runing the short FlexSim code.

pic1

Unfortunately I have a FlexSim model, which was created befor FlexSim DBConnector was implemented. Due to this I need to use ODBC. I created an new DSN in ODBC, wich could found my SQL database successelful. But I cannot open the database in FlexSim via ODBC. I wrote a short Flexsim Command to illustrad it. I get a exception. You can see it on picture 2 and 3.

pic 2

pic 3

Maybe you have any idea to solve the issue. The exception is not helpful for me.

Feel free to ask me anything about my system. I am looking forward to your solution. Excuse my english skill. I am not a native speaker.

Best regards

Ben

FlexSim 18.2.2
sqldatabaseodbc
· 7
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

You said, "Unfortunately I have a FlexSim model, which was created befor FlexSim DBConnector was implemented."

Can you not open that model in a version of FlexSim where the DBConnector is available?

Models built in older versions of FlexSim should open and upgrade to newer versions just fine.

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ commented ·

Also, did you try following the steps in this tutorial? Perhaps something described there can help you understand what is misconfigued.

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Phil BoBo ♦♦ commented ·

As that tutorial explains the DSN should be added using odbcad32.exe found at %windir%\syswow64\odbcad32.exe or %windir%\system32\odbcad32.exe depending on whether you're connecting via 32bit or 64 bit FlexSim.

0 Likes 0 ·
Ben K2 avatar image Ben K2 commented ·

It is a complex model, wich was designed in FlexSim 7.3.. Now I am using a new computer with Flexsim 18.2.. So it would be to much work to use DBConnector instead of the "dbopen" commands.

I am reinstalled the ODBC connector and used the newest version. Futhermore I payed attention for the right architecture. Both are 64 bit versions. I reached a small goal:

"dbopen("flexsimdata","productionplan",1);" does not return a error anymore. But it returns the value 2. You can see it on the screenshot. This commands should give 1 for success, 0 otherwise.

Any interact with the SQL datenbase still does not work. You can see a error on the secound screenshot. The cell exist in row 2 and col 2. So this is not the error.

0 Likes 0 ·
4.png (9.2 KiB)
5.png (63.1 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦ Ben K2 commented ·

It looks like the mode is returned so 2 for table, 1 for SQL. Can you try in SQL mode rather than table mode?

dbopen("flexsimdata","SELECT * FROM productionplan",0);  //could also be SELECT NULL
dbsqlquery("UPDATE productionplan SET Wickelfertigung=2 WHERE ID=2");
dbclose();
0 Likes 0 ·
Ben K2 avatar image Ben K2 Jason Lightfoot ♦ commented ·

I tried your code. When I open the smulation and run the code for the first time, then I do not get any error message and the "Value" is change d to 0. But there is nothing changed in my sql table. When I run the code again, I get the a error message "exception: FlexScript exception: /0 c: /testlink_instance i: /testlink_associated".

0 Likes 0 ·
Show more comments

1 Answer

·
Phil BoBo avatar image
0 Likes"
Phil BoBo answered Felix G2 commented

If you don't want to upgrade your model to 18.2, you can simply just continue to run this model in FlexSim 7.3.6.

You can install FlexSim 7.3.6 and FlexSim 18.2 on the same computer with the same license. A FlexSim license will work for any and all FlexSim versions <= the version of the license.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Felix G2 avatar image Felix G2 commented ·

I tried the exact same code (and same ODBC-configuration, same MySQL-Database) meaning dbsettablenum in Flexsim 18.2.2 and Flexsim 7.3.6. It works fine in the older version but not in the newer one. This is really strange.. Might this be some bug in the newer version?

Also: Getting data from the database, e.g. with dbgettablenum, works (for both versions).

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Felix G2 commented ·

FlexSim 17.1.0 included the following bug fix:

  • Fixed an issue with writing to Access databases with read-only fields.

This changed the code in dbsettablenum().

It is possible that this bug fix introduced the issue you are experiencing.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.