From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a connection string for CVI/SQL Toolkit when connecting to SQL Server 2008

Solved!
Go to solution

I have been trying to connect to my MS SQL Server 2008 database for two days using the CVI/SQL Toolkit with no luck.  I am using the DBConnect function and I have tried many different formats for the connection string with no luck.  I get a "SQL Server does not exist or access denied" error after a long pause when trying to connect.  Does anyone know what the proper format is for this string?  I have even setup a SQL Server on my local machine and I still have not been able to get the correct format for the connection string.

 

-Tom 

0 Kudos
Message 1 of 16
(6,281 Views)

Hi Tom, 

 

If you are sure the problem is with the connection string this website may help?

 

I'm no db expert but maybe there are settings in the database that needs to be adjusted, too.

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 16
(6,265 Views)
I appreciate the response, but I have looked through many websites including that particular one.  After trying pretty much every logical variation from those sites I still have been unable to connect to the database.  I fear that this is because these are generic connection string websites and somehow the CVI/SQL Toolkit is using a driver that is not covered in these sites.  I'm not really sure why it is not working, but I am just hoping someone out there has used the Toolkit to connect to a MS SQL Server 2008 DB and knows what the connection string should look like.
0 Kudos
Message 3 of 16
(6,253 Views)

Hi Tom,

 

You may have already tried this, but what about the  CVI SQL Toolkit Help?  You can find this under Programs>>National Instruments>>SQL Toolkit for CVI.  This has a section titled Connection to a Database.  Let me know if you've already tried this without success or if it doesn't work.

 

Cheers, 

 

Message Edited by Michael_W. on 03-23-2010 12:34 PM
0 Kudos
Message 4 of 16
(6,239 Views)

Do you mean the section entitled: Connecting to a Database? That consists of:

 

Connecting to a Database

Use DBConnect to connect to a data source. The only parameter is a connection string, which must contain the data source or provider name and any other attributes the database requires. DBConnect returns a handle to the database connection that other functions in the toolkit use. Call DBDisconnect to close the database connection, passing in the database connection handle from DBConnect. The following code is a simplified version of the code found in connect.prj.

int hdbc = 0; /* Handle to database connection. */

int rescode; /*Result code. */

/* Connect to CVI_Samples data source. */

hdbc = DBConnect ("DSN=CVI Samples");

if (hdbc <= 0) goto Error;

...

/* Disconnect from database. */

resCode = DBDisconnect (hdbc);

if (resCode != DB_SUCCESS) goto Error;

 

 

Yeah it is even less help haha, a terrible example that they give for a connection string 

0 Kudos
Message 5 of 16
(6,236 Views)

Well, I also figured out later that the CVI connection string is different than the ones referred in the website I linked to.

 

That may be so, because first you need to configure the database from Control Panel > Administrative Tools > Data Sources.

The connection string is related to the name you give to the data source.

 

In the example code I took from a colleague there is also a call to DBActivateSQL before other functions are called for accessing/modifying the database.

May your code be missing that?

S. Eren BALCI
IMESTEK
0 Kudos
Message 6 of 16
(6,215 Views)

What program are you referring to using when configuring the DB?  Neither MS SQL Server Management Studio nor SQL Server Configuration Manager, which are the two programs I know to use when setting up and configuring the DB, have a "Control Panel" item in the menu bar.  That being said, I do believe that my Data Source attribute in the connection string is being set correctly, but at this point I am questioning everything about how I am trying to connect.

 

The DBActivateSQL appears to be part of the process necessary to prepare a SQL Statement.  This is the function help window:

 

 

 

Activates an SQL statement. Calling DBActivateSQL is equivalent to calling DBNewSQLStatement and then DBOpenSQLStatement.

NoteNote  To use SQL parameters, you must use DBPrepareSQL and DBExecutePreparedSQL instead of DBActivateSQL.

Example

hdbc = DBConnect ("DSN=CVI32_Samples");

...

hstmt = DBActivateSQL (hdbc, "SELECT * FROM TESTLOG");

...

resCode = DBDeactivateSQL (hstmt);

resCode = DBDisconnect (hdbc); 

0 Kudos
Message 7 of 16
(6,203 Views)

I am refering to the standard Windows Control Panel that you open from Start > Settings > Control Panel.

 

The sample program I have (which is an application actively used in facility) uses an Access database and it is configured from the Data Sources (ODBC) panel of Windows. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 8 of 16
(6,194 Views)
Solution
Accepted by topic author TJank
I have successfully connected to the database, thank you all for your help.  It was a combination of syntax errors and configurations that needed to be changed.
0 Kudos
Message 9 of 16
(6,173 Views)

Hi,

 

I am also facing the same issue,can u pls give the connection string u used here or if possible can u zip me the whole application here?...its somewhat urgent

0 Kudos
Message 10 of 16
(5,307 Views)