LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Server connection

I am trying to make a connection to a remote SQL Server database. I've created a UDL and it seems to work fine. However, the name of my database will change occasionally. I can use the Windows Data Source Administrator to change the default database name. I want to change the name of the database within LabVIEW at run time. How do I make a database connection without doing something at the OS data source level?
0 Kudos
Message 1 of 2
(2,935 Views)
This is an extraction from MSDN article

Using ODBC with Microsoft SQL Server
Amrish Kumar and Alan Brewer
Microsoft Corporation

September 1997


"ODBC data sources contain information that tells a driver how to connect to a database. ODBC data sources can be created by using the ODBC Administrator application in Control Panel or by an application calling the ODBC SQLConfigDataSource function.

Data source definitions are stored in C:\Windows\System\Odbc.ini for the Microsoft Windows� version 3.x and Windows for Workgroups version 3.x operating systems.

Win32 data sources fall into one of two categories (for details, see Microsoft Knowledge Base article Q136481):

Windows NTuser-specific data sources and Windows 95 data sources
On the Microsoft Windows NT� operating system, user data sources are specific to the Windows NTaccount under which they were defined. User-specific data sources are not always visible to applications running as Windows NT services. Windows 95 data sources are stored in the following registry key:
HKEY_CURRENT_USER\Software\ODBC\Odbc.ini.

Windows NT�system data sources
On Windows NT, system data sources are visible to all Windows NTaccounts on the computer. System data sources are always visible to applications running as Windows NTservices. The ODBC driver manager that ships with Microsoft Office 97 also supports system data sources on Windows 95 clients. Windows NTsystem data sources are stored in the following registry key:
HKEY_LOCAL_MACHINE\Software\ODBC\Odbc.ini.

Information about the drivers installed on a client is stored in C:\Windows\System\Odbcinst.ini in Windows 3.x or Windows for Workgroups 3.x and in HKEY_LOCAL_MACHINE\Software\ODBC\Odbcinst.ini in Windows NTand Windows 95.

Each driver needs to store driver-specific information in its data sources. When a user adds a data source using ODBC Administrator, the driver displays a dialog box, where the user specifies data source information. When a data source is defined with SQLConfigDataSource, the function accepts an attribute string parameter that can contain driver-specific keywords. All of the SQLConfigDataSource driver-specific keywords for the SQL Server ODBC driver have counterparts in the dialog box that displays when using ODBC Administrator.

Here's an example SQLConfigDataSource call that sets up a SQL Server data source referencing a server using DHCP on TCP/IP:

RETCODE retcode;
UCHAR *szDriver = "SQL Server";
UCHAR *szAttributes =
"DSN=my65dsn\0DESCRIPTION=SQLConfigDSN Sample\0"
"SERVER=my65server\0ADDRESS=HRServer\0NETWORK=dbmssocn\0"
"DATABASE=pubs\0";
retcode = SQLConfigDataSource(NULL,
ODBC_ADD_DSN,
szDriver,
szAttributes);
"

If you need more information send email to waldemar@hersacher.de.

Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 2 of 2
(2,935 Views)