LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Register ODBC using Distribution Kit

I get the fun job of trying to figure out how to distribute my CVI application with an ODBC database file. Since my target machines run XP, how can I install and register my database using the CVI Distribution Kit? Or is this not even possible? I'd like to not have to go to a third party installer (like Wise) because my app needs the CVI RTE and the Report Instrument Driver (which needs to be registered as an ActiveX server). Building this outside of CVI sounds brutal. But I don't want to tell my users to go to the conrol panel and set up an ODBC source. I've looked into command line registration, but haven't figured it out yet. Has anyone else tried this?
0 Kudos
Message 1 of 7
(4,380 Views)
You can build a File DSN, which you can use to point to the database. Then, in the distribution kit, just add the dsn file to the kit and installation. Also, in your application access it using the DBConnect string and some connection parameters. Take a look at this knowledgebase entry on programmatically specifying a file as a dsn. It should get you going in the right direction. Hope this helps!!
Jeremy L.
National Instruments
Message 2 of 7
(4,364 Views)
Hello

We don't have anything special built into the CVI Dist kit for this. I'm not sure how to manually distrbute a ODBC db, but you can include bat files and other exe ( if you need to distribute ADO , MDAC or file DSNs) with the distribution kit as file groups, and specify which executable or command to run after the install is complete.

Again, your distrbution requirements would depend on the type of db that you are talking to (Access, SQL server, php). Once you find out what the procedure is and which files the db requires for distribution, you can customize the CVI dist kit for this task.

Hope this helps.
Bilal Durrani
NI
0 Kudos
Message 3 of 7
(4,362 Views)
Jeremy,

Your advice worked well. But this has presented me with a new (but related) challenge.

I need to get the current working directory of my app so that I can programmatically build the DBConnect Connection String (the database will be installed in the same directory as my .exe). But when I get the current directory using GetProjectDir, it is a path with single backslashes. The DBConnect Connection String is a string, so I need to convert those pesky single backslashes to double backslashes. This has turned out to be harder than I expected. There must be a trick to do this and I am not clever enough to figure it out. Can you please save my sanity and give me hint what to look at?
0 Kudos
Message 4 of 7
(4,348 Views)
Are you sure you need to double-slash the path? The purpose of double-slashing is to tell the compiler whether you're entering a backslash code (which is stored as a single character) or a literal backslash character. But once the string is stored, a backslash character is a backslash character.
For example,
strcpy(myPath, "c:\\application Data\\0001");
// myPath now contains c:\application Data\0001
// Now both \'s are literal characters:
// \a is two characters, not the single character alert (bell)
// \0 is two characters, not the single character NULL

But, if your DBConnect Connection String requires double-backslashes (and I don't know if it does), the general idea is to copy your existing string to a new string, one character at a time, and if the current character in the existing string is a \, add another one to your new string.

Try something like this.

// remove the spaces after the < (I added them to fool the forum's HTML error detection)
#include < ansi_c.h>
#include < utility.h>

main()
{
char singleSlashPath[MAX_PATHNAME_LEN];
char doubleSlashPath[MAX_PATHNAME_LEN];
int i, j=0;

strcpy (singleSlashPath, "c:\\my documents\\my project");
for (i=0; i < strlen(singleSlashPath); i++)
{
// copy a character from singleSlashPath to doubleSlashPath
// then increment the doubleSlashPath index
doubleSlashPath[j++] = singleSlashPath[i];
if (singleSlashPath[i] == '\\')
// add another \ then increment the doubleSlashPath index
doubleSlashPath[j++] = '\\';
}
doubleSlashPath[j] = '\0'; // terminate doubleSlashPath

}
Message 5 of 7
(4,344 Views)
I would take a look at Al's post. This is what you're seeing. What you could do is build the connection string in a variable using the string functions (strcat, strcpy, etc.). Then on your DBConnect, instead of passing the string constant ("DSN= "etc...) just pass the string variable. That should work just fine for you.
Jeremy L.
National Instruments
0 Kudos
Message 6 of 7
(4,333 Views)
Hello,

Another way to insert an extra backslash would be to tokenize the string path based on backslashes. Both implementations are going to be O(n) whether it be at the CVI level or at the system level, but tokenizing reduces the amount of code you see.

i.e.

#include
#include

int main (int argc, char *argv[])
{
int fileSize;
char * testPath = "C:\\test1\\test2\\test3\\test4\\test5\\test6\\";
char * origPath = "C:\\test1\\test2\\test3\\test4\\test5\\test6\\";
char finalPath [50] = "";
char * token;

\\ Tokenize input string according to backslashes (\)
token = strtok (testPath, "\\");
while (token != NULL) {
\\ Create the new string with double backslashes
sprintf(finalPath, "%s%s\\\\", finalPath, token);
token = strtok(NULL, "\\");
}

printf("%s\n%s\n", origPath, finalPath);
return 0;
}
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 7 of 7
(4,326 Views)