Thread View: microsoft.public.data.odbc
1 messages
1 total messages
Started by Paul Maia
Sun, 14 Apr 2002 23:28
SQLConfigDataSource: trying to remove a DSN
Author: Paul Maia
Date: Sun, 14 Apr 2002 23:28
Date: Sun, 14 Apr 2002 23:28
109 lines
5168 bytes
5168 bytes
I am trying roll my own un-installer. Yep, I know... There are
a lot of tools out there for this, but I want to do it myself.
What better way to learn! After 25 years in this industry, I
still want to learn... Things were so simple with Turbo Pascal
1.0 on DOS, in the 70's!
I am running C++ Builder 5.0, with all patches. Windows 2000
is the dev environment, test environment is Windows 2000 and
Windows 98.
I have ACCESS database connectivity in my app. I know, SQL
would be better, but I have ACCESS and it works (or maybe it
doesn't) so... hmm... OK.
I have included the code that I am using... I have cut some
pieces to make the code more readable and less verbose.
Here's the problem... See CreateTest() below. The creation of
the DSN works as prescribed. The DSN is created. I have confirmed
this in the ODBC utility, in the Control Panel.
When I call (see below) RemoveTest(), I get an error 11,
ODBC_ERROR_REQUEST_FAILED, a generic error that indicates
that the underlying ConfigDSN() has failed. Hmm... Not a lot of
help, there.
I have tried this on Windows 2000 and Windows 98 SE. I have also
tried adding all of the attributes (applicable ones, anyway) that
I used in the Create function, but to no avail...
I am using ODBC 3.5xxx on both systems.
Have I done something stupid? Or is there something I just don't
understand? Hmm... Both I suspect... Any clues???
Now the code....
---------------------------------------------------------------
BOOL Create_MSAccess_DSN(char *dsn, char *path, char *db_name,
char *description)
{
char szAttributes[MAX_PATH * 2 + 200];
int retCode = 0;
DWORD errNum;
char msg[SQL_MAX_MESSAGE_LENGTH];
// Build attribute string
sprintf(szAttributes, "DSN=%s;FIL=MS Access;JetIniPath=odbcddp.ini;"
"DBQ=%s;DefaultDir=%s;Description=%s;UID=;PWD=;;", dsn,
db_name, path, description);
// Now replace the semi's with Nulls per the spec
CreateAttributeString(szAttributes);
// go create it
retCode = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, driver,
szAttributes);
// any error?
if (retCode == 0)
{
memset(msg, 0, sizeof(msg));
SQLInstallerError(1, &errNum, msg, sizeof(msg), NULL);
}
// did it work? 0 is failure
return(retCode);
}
//---------------------------------------------------------------------------
// deletes/removes a Microsoft Access ODBC DSN
// returns >0 on success or 0 on failure
// NOTE: db_name needs to be a fully qualified path to the DB
BOOL Remove_MSAccess_DSN(char *dsn, char *path, char *db_name)
{
char szAttributes[200]; // a DSN, and some extra
int retCode;
DWORD errNum;
char msg[SQL_MAX_MESSAGE_LENGTH];
// Build attribute string
sprintf(szAttributes, "DSN=%s;;", dsn);
// Now replace the semi's with Nulls per the spec
CreateAttributeString(szAttributes);
// go create it
retCode = SQLConfigDataSource(Application->Handle,
ODBC_REMOVE_DSN, driver, szAttributes);
// any error?
if (retCode == 0)
{
memset(msg, 0, sizeof(msg));
SQLInstallerError(1, &errNum, msg, sizeof(msg), NULL);
}
// did it work? 0 is failure
return(retCode);
}
void CreateTest()
{
if (Create_MSAccess_DSN("Fred", "D:\\Databases", "D:\\Databases\\Data.MDB",
"Database For Repeater-Decoder Monitor"))
MessageBox(NULL, "Returned TRUE", "Create_MSAccess_DSN", MB_OK);
else
MessageBox(NULL, "Returned FALSE", "Create_MSAccess_DSN", MB_OK);
}
void RemoveTest()
{
if (Remove_MSAccess_DSN("Fred", "D:\\Databases", "D:\\Databases\\Data.MDB"))
MessageBox(NULL, "Returned TRUE", "Remove_MSAccess_DSN", MB_OK);
else
MessageBox(NULL, "Returned FALSE", "Remove_MSAccess_DSN", MB_OK);
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads