LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

connect to SQL Server without a DSN

Can I connect to a SQL Server database without using a DSN? I am using the following connection string:
Provider=MSDASQL.1;Extended
Properties="DRIVER={SQL Server};SERVER=AT-CAL\SQL1A;READONLY=0;DATABASE=Calib"
as an input to DB Tools Open Connec (String).vi.
It produces the following error:
DB Tools Open Connec (String).vi->Untitled 2Exception occured in Microsoft OLE DB Provider for ODBC Drivers, [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified. in DB Tools Open Connec (String).vi->Untitled 2
Is there something wrong with this connection string?
0 Kudos
Message 1 of 4
(3,990 Views)
I won't say you have a problem with the connection string, but using a connection defined in ODBC Administrator (thus creating a DSN) makes the LABView code cleaner and more flexible. It should also allow you to verify the DB connection outside of LABView. Once the connection to the DB is verified, if you include the UID and PWD in the ODBC config, you simply pass the DSN to the LV connection VI. I connect to DB's under a variety of DB drivers and have very reliable connections. If the app doesn't connect, it's easy to go back to the ODBC Admin and check what's happening. Rarely is the problem LV related -- something changed for the DB connection.

Happy wiring!

Russ
0 Kudos
Message 2 of 4
(3,990 Views)
Thanks for the opinion. I agree that using a DSN has many advantages, but it is my customer's requirement that the connection be made without using a DSN.

Allen
0 Kudos
Message 3 of 4
(3,990 Views)
I think I found a method that you can use to make sure you build up the correct string. I have never done this before so I decided to see what string the VI used, rather than play with the format of your string.

Take a look at the attached VI. I simply modified the DB Open Connection VI to tell me the connection string it used.

So you can use this VI to figure out the right string to use by testing it on a File DSN. So on your PC create the File DSN and then use it in this VI. After you have run it you will have the string it actually used.

Theoretically you can then just use that string, or at least see what was wrong with the string you where using. When I ran it and then looked at the difference between our strings, the main difference I say was
that mine had a path to the Database to be used.

Let me know if you have any questions.

Evan
National Instruments
0 Kudos
Message 4 of 4
(3,990 Views)