LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a DSN programmatically

Hi,

Could someone tell me if there is a way to create a DSN programmatically with MySQL ODBC driver from LV 7 Express?

Thanks in advance,

ToNi.
0 Kudos
Message 1 of 12
(6,777 Views)
You can create a connection string  dynamically.  Take a look at http://www.connectionstrings.com/ under the MySQL >> ODBC section, shown below:

ODBC 2.50 Local database:
"Driver={mySQL};Server=localhost;Option=16834;Database=mydatabase;"

ODBC 2.50 Remote database:
"Driver={mySQL};Server=data.domain.com;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;"

ODBC 3.51 Local database:
"DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=myDatabase;USER=myUsername;PASSWORD=myPassword;OPTION=3;"

ODBC 3.51 Remote database:
"DRIVER={MySQL ODBC 3.51 Driver};SERVER=data.domain.com;PORT=3306;DATABASE=myDatabase; USER=myUsername;PASSWORD=myPassword;OPTION=3;"
0 Kudos
Message 2 of 12
(6,752 Views)
If you want to create a file DSN, this should be fairly simple - if you open a DSN file (they're usually in program files\common\ODBC\data sources) in notepad, you will see that it is a simple ASCII file, which you can probably rebuild yourself. You can probably also find a documentation of the file structure on the internet. A system DSN will probably be more complex as they are probably saved in the database.

___________________
Try to take over the world!
0 Kudos
Message 3 of 12
(6,681 Views)
 
0 Kudos
Message 4 of 12
(6,736 Views)
Thanks very much,

Could you attach here a little example about it please? I don't know exactly how to implement it in LV 7 express.

Thanks,

ToNi
0 Kudos
Message 5 of 12
(6,734 Views)
Like I said, it's basically just an ASCII configuration file, so you can use the configuration file VIs to edit it, as you can see in this example. The example only shows reading, but you can write just the same. You should open a DSN file yourself to look at the key names and values.

___________________
Try to take over the world!
0 Kudos
Message 6 of 12
(6,731 Views)
Thanks very much tst,

I think another idea to create a System DSN, If I Would know to add the following entries to the windows registry.... then I could create a System DSN easyly:

[Registry]
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ODBC Data Sources; ValueType: string; ValueName: SBRs_dades; ValueData: MySQL ODBC 3.51 Driver; Flags: createvalueifdoesntexist uninsdeletevalue
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\SBRs_dades; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Driver; ValueType: string; ValueData: C:\WINDOWS\system32\myodbc3.dll
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\SBRs_dades; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: DATABASE; ValueType: string; ValueData: sbrs_dades
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\SBRs_dades; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: DESCRIPTION; ValueType: string; ValueData: Dades dels SBRs
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\SBRs_dades; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: PASSWORD; ValueType: string; ValueData: **************
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\SBRs_dades; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: SERVER; ValueType: string; ValueData: localhost
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\SBRs_dades; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: USER; ValueType: string; ValueData: root

*********************************************************************************

How can I add these entries to the windows registry from LV 7 Express?

Thanks,

ToNi.
0 Kudos
Message 7 of 12
(6,726 Views)

The registry VIs can be found in the Advanced palette. If you search the example finder, you should probably find some examples.


___________________
Try to take over the world!
0 Kudos
Message 8 of 12
(6,725 Views)
Thanks,

One thing, how can I set up the flags for an item with Write Registry Value Simple.vi placed in Advanced->registry? For example the flags of this entry:

Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ODBC Data Sources; ValueType: string; ValueName: SBRs_dades; ValueData: MySQL ODBC 3.51 Driver; Flags: createvalueifdoesntexist uninsdeletevalue


ToNi.
0 Kudos
Message 9 of 12
(6,721 Views)
Looks like you can't. Personally, I don't see any flags when I look at my data using Regedit, and I don't really know that much about the registry, so I can only guess what those flags do.

___________________
Try to take over the world!
0 Kudos
Message 10 of 12
(6,718 Views)