How Do I add DSN programatically (non-MFC)? 
Author Message
 How Do I add DSN programatically (non-MFC)?

I just need to add a DSN.  Does anyone have any suggestions?


Tue, 17 Jul 2001 03:00:00 GMT  
 How Do I add DSN programatically (non-MFC)?

Quote:

> I just need to add a DSN.  Does anyone have any suggestions?

I suggest you call SQLConfigDataSource.


Tue, 17 Jul 2001 03:00:00 GMT  
 How Do I add DSN programatically (non-MFC)?
You could create a DSN programmatically using the ODBC API
SQLConfigDataSource.

The following code snippet creates a DSN for an Access mdb programmatically
:

* The variable tempstr holds the name of the mdb.
* The variable m_EditFilePath holds the entire path of the file. ( Got from
CFileDialog )

  char *szDesc;
  szDesc = new char[256];
 CString tempstr =
dlg.m_EditFilePath.Left(dlg.m_EditFilePath.ReverseFind('\\'));
 sprintf(szDesc,"DSN=%s!DESCRIPTION=Access Sample
DSN!DBQ=%s!FIL=MicrosoftAccess!             DEFAULTDIR=%s!!","DSN
Name",dlg.m_EditFilePath,tempstr);

  int 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))
   MessageBox("Creation of Source DSN for Access MDB
Failed","INFORMATION",MB_OK);
  else
   MessageBox("Creation of Source DSN for Access MDB
Succeeded","INFORMATION",MB_OK);

In case U need it for Excel or Text files, the parameters passed differ.

Regards,
Sukanya Swaminathan
Aditi Technologies Pvt. Ltd
224/16, Ramana Maharishi Road,
Blore - 80

Quote:

>I just need to add a DSN.  Does anyone have any suggestions?



Sat, 28 Jul 2001 03:00:00 GMT  
 How Do I add DSN programatically (non-MFC)?

Quote:

>You could create a DSN programmatically using the ODBC API
>SQLConfigDataSource.

>The following code snippet creates a DSN for an Access mdb programmatically
>:

>* The variable tempstr holds the name of the mdb.
>* The variable m_EditFilePath holds the entire path of the file. ( Got from
>CFileDialog )

>  char *szDesc;
>  szDesc = new char[256];
> CString tempstr =
>dlg.m_EditFilePath.Left(dlg.m_EditFilePath.ReverseFind('\\'));
> sprintf(szDesc,"DSN=%s!DESCRIPTION=Access Sample
>DSN!DBQ=%s!FIL=MicrosoftAccess!             DEFAULTDIR=%s!!","DSN
>Name",dlg.m_EditFilePath,tempstr);

>  int 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))
>   MessageBox("Creation of Source DSN for Access MDB
>Failed","INFORMATION",MB_OK);
>  else
>   MessageBox("Creation of Source DSN for Access MDB
>Succeeded","INFORMATION",MB_OK);

>In case U need it for Excel or Text files, the parameters passed differ.

>Regards,
>Sukanya Swaminathan
>Aditi Technologies Pvt. Ltd
>224/16, Ramana Maharishi Road,
>Blore - 80


>>I just need to add a DSN.  Does anyone have any suggestions?

There's another way to do that. You can write your DSN directly into the registry, just under CURRENT_USER\Software\ODBC\ODBC.ini
take a look on the already created DSN's and write your own.

-----------------** -- Posted from CodeGuru -- **-----------------
http://www.codeguru.com/    The website for Visual C++ programmers.



Thu, 09 Aug 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to add an MFC CWnd to a non-MFC app

2. Adding MFC support to my non-MFC application

3. MSVC6: Help adding MFC to non-MFC App

4. Adding MFC to non-MFC Application

5. Adding MFC-code to a non MFC Application(WIN-application)

6. How to create an ODBC DSN programatically ?

7. Create DSN to Oracle ODBC Driver Programatically- HOW?

8. Programatically Creating System DSN's

9. User DSN vs Sys DSN vs File DSN.

10. Problem adding non-MFC Classes to project

11. Add text to control from non-MFC class

12. How to add DSN

 

 
Powered by phpBB® Forum Software