Applies To:
  • CitectSCADA 6.00
  • CitectHMI 6.00

Summary:
On a remote client (Full, IDC or Web), I want the user to be access a database, but I am not able to configure the DSN on the client machine. Is there a way to connect to a database without defining a DSN? 

Solution:
Use a FileDSN,

This can be used by Citect without defining a normal DSN as follows

- Create a File DSN (this can be done using the ODBC Administrator --> File DSN --> Add...)

- put the .DSN file that is created in your project dir (or any standard dir on all the clients)

- In CiCode use --> SQLConnect("FILEDSN=" + sPath); where sPath contains the full path to the .DSN file (e.g. "C:\OurSQLConn.dsn")

You can also use something like --> PathToStr("[RUN]:\OurSQLConn.dsn") if you want more flexibility in paths (remember you can add your own path substitutions with the [Path] Alias=C:\Anydir\Anydir)

Solution courtesy of Jeroen Brattinga, Bouwhuis Regeltechniek, Zwolle Netherlands

Use a Registry File to dynamically create a DSN

You can generate a file similar to the following settings by exporting from HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI, then clipping out what you don't want on the target machines. I have provided an example below.

You can apply the changes from Cicode - something like

exec("regedit.exe addDSN.reg");

---clip here---
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI]
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources] "SERVER_PCA"="SQL Server"
"SERVER_PCB"="SQL Server"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SERVER_A]
"Driver"="C:\\WINNT\\System32\\SQLSRV32.dll"
"Description"="SERVER_A"
"Server"="10.0.1.201"
"LastUser"="ct_user"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SERVER_B]
"Driver"="C:\\WINNT\\System32\\SQLSRV32.dll"
"Description"="SERVER_B"
"Server"="10.0.2.202"
"LastUser"="ct_user"
---clip here---

Solution courtesy of Chris Ghormley, Setpoint Control, Portland USA

 

Keywords:
 

Attachments