Originally posted by: D Sole
I know that this was mentioned in other comments, but I wanted to have it in the title, so it would be noticed better.
Don't use the ':' character , when replacing with '\0', it will replace the ':''s in your paths to the database.
Use something else, such as $ which cannot be in a path.
ReplyOriginally posted by: Prashant Jani
szDesc=new char[256];
the code works perfect.
however there was something overlooked. the ':' is being replaced by a '\0'.
the path to databse may contain a ':'. this will also be replaced by a '\0'. thus the path would not be specified correctly.
here the change has to be made. replace the':' by any other char which is not likely to be included in the database path.
i am giving the modified version:
char* szDesc;
int mlen;
sprintf(szDesc,"DSN=%s$ DESCRIPTION=Client data$ DBQ=%s$FIL=MicrosoftAccess$ :: ","Client",argv[1]);
mlen = strlen(szDesc);
for (int i=0; i<mlen; i++)
{
if (szDesc[i] == '$') szDesc[i] = '\0';
}
if (FALSE ==SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
printf("DSN Creation Failure");
// code was run from cmd prompt
else
printf("DSN Creation Successful");
}
Originally posted by: Alwin Beukers
bool CMainFrame::SetDataSource(CString &strDSN, CString &strPath)
char szDSN[256];
TRACE("Datasource configuration failed\n");
}
return true;
In my applications I use this:
{
sprintf(szDSN, "DSN=%s%cDBQ=%s%c",
strDSN,
NULL,
strPath,
NULL);
if (!SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", szDSN)) {
return false;
}
Originally posted by: rafi
Hi,
In my application i have to get the database name from the user. I have an file which has set of database & its associated driver in it. If a user enters the database i first check the availability, if so i create the database with the information i have captured in the file. Generally the file contains the database name & its associated drivername only. Its working fine in my application & i found the DSN in the registry. One thing i have doubt whether all rdbms & dbms related things can be used in single SQLCONFIGDATASOURCE() function. One more doubt is in SQLCONFIGDATASOURCE() there is an argument called lpz_attrubutes, in that what do u mean by ADDRESS=" "\0NETWORK=" ". Would u tell me clearly...
rgds
rafi
Originally posted by: Girish H RamaMohan
Actually it's very easy method.
ReplyOriginally posted by: Wasim Ansari
dear friend,
i am a novice vc++ programmer, i am developing a database
management program for financial accounting with inventory control, please suggest me the way from where i can get a detailed help, like a readymade sourcecode for the same.
thanks and hoping for your kind cooperation.
Originally posted by: Raul
UsersDB.CreateDatabase(NULL,
CreateDatabase is a function of my own that simplifies the process, but it passes all the arguments to SQLConfigDataSource JUST AS THEY ARE. This seems ridiculous but, isn't Windows and all its related stuff?
By the way, does anyone know how to read a comma-delimited text file into a table? Thanks.
I have never had problems when using SQLConfigDataSource(). Maybe that's because I write my code (for the sake of clarity) like this:
ODBC_ADD_DSN,
ACCESS,
"Microsoft Access Driver (*.mdb)",
"DSN=Users Records\0"
"Description=USers Records\0"
"Fil=MS Access\0"
"DataDirectory=D:\\Files\\UFiles\0"
"DBQ=D:\\Files\\UsersList.mdb\0",
UsersFile);
Originally posted by: Murat Uenalan
It really creates the DSN automatically, but when i try
to connect to the source i get panic because it says
"undefined data source, unknown driver ...etc".
May be a ODBC Manager Version conflict ?
Originally posted by: David Orr
Has anybody successfully programmatically created a DSN to access an MS SQL Server database?
ReplyOriginally posted by: Dave Emmith
My code looks like this:
char* szDesc;
if (FALSE == SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)\0", (LPCSTR)szDesc))
CDialog::OnOK();
Because my users will probably be connecting to a database on a different drive I changed the search-and-replace loop's ':' with a ';'. Otherwise, what you will end up with is an invalid path to your data source. For instance, if the database resides on 'U:\databases' you will get a 'U\' as the path, which of course, is invalid.
void CODBCDlg::OnOK()
{
CWnd::UpdateData(TRUE);
ASSERT(m_DSN != "");
ASSERT(m_DbFilename != "");
ASSERT(m_DefaultDirectory != "");
int mlen;
szDesc = new char[256];
sprintf(szDesc,"DSN=%s; DESCRIPTION=%s; DBQ=%s; FIL=MicrosoftAccess; DEFAULTDIR=%s", m_DSN, m_Description,
m_DbFilename, m_DefaultDirectory);
mlen = strlen(szDesc);
for (int i = 0; i < mlen; i++)
{
if (szDesc[i] == ';')
szDesc[i] = '\0';
}
MessageBox("Failed", "SQLConfigDataSource", MB_OK);
else
MessageBox("Successful", "SQLConfigDataSource", MB_OK);
}