03-22-2010 12:40 PM
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
Solved! Go to Solution.
03-23-2010 01:00 AM
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.
03-23-2010 07:21 AM
03-23-2010 12:33 PM - edited 03-23-2010 12:34 PM
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,
03-23-2010 12:42 PM
Do you mean the section entitled: Connecting to a Database? That consists of:
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
03-24-2010 04:16 AM
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?
03-24-2010 07:16 AM
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.
Note To use SQL parameters, you must use DBPrepareSQL and DBExecutePreparedSQL instead of DBActivateSQL. |
hdbc = DBConnect ("DSN=CVI32_Samples");
...
hstmt = DBActivateSQL (hdbc, "SELECT * FROM TESTLOG");
...
resCode = DBDeactivateSQL (hstmt);
resCode = DBDisconnect (hdbc);
03-24-2010 08:50 AM
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.
03-24-2010 04:31 PM
01-22-2013 06:36 AM
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