|
-
April 26th, 1999, 04:01 PM
#1
Using SQLDataSources to get DSN List
Hi there:
I am trying to use SQLDataSources to get a list of all the DSN configured on a computer. I am using the following code but the program keeps crashing. Any ideas?
RETCODE retcode;
HENV henv;
UCHAR FAR *DataSourceNames;
SWORD FAR *pcbDSN;
unsigned char *szDescription;
SWORD FAR *pcbDescription;
retcode = SQLAllocEnv(&henv);
if(retcode != 0)
{
AfxMessageBox("SQLAllocEnv Error");
return;
}
// I managed to get pass the SQLAllocEnv function with no errors but immediately
// crashed the program with the next function.
retcode = SQLDataSources(henv,
SQL_FETCH_FIRST,
DataSourceNames,
1024,
pcbDSN,
szDescription,
255,
pcbDescription);
Thanks in advance.
Teik
-
April 27th, 1999, 12:36 PM
#2
Re: Using SQLDataSources to get DSN List
This section of code works for me.
HENV hEnv;
UCHAR tmpDSN[256];
SWORD tmpDSNLen = 255;
SWORD ResultLen;
UCHAR tmpDriver[256];
SWORD tmpDriverLen = 255;
SWORD ResultDescLen;
RETCODE ReturnCode = SQL_SUCCESS;
ReturnCode = ::SQLAllocEnv(&hEnv);
if (SQL_SUCCESS == ReturnCode)
{
ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_FIRST, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);
// additional processing
}
It seems to me that you are not allocating space to store the variables that are set in during the
functions executions. A pointer to an SWORD is not the same as creating an SWORD. For sure this is true with your unsigned char string, the pointer does not allocate the space needed when the function puts the driver description in the variable so a memory overwrite occurs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|