CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: ODBC DB Path

  1. #1
    Join Date
    Jun 2003
    Location
    India
    Posts
    29

    ODBC DB Path

    Hello All,

    Which is the function, that can give information on the database path accessed by a DSN?

    Thanks & Regards
    Ms. Rajmathi

  2. #2
    Join Date
    Nov 2004
    Posts
    20

    Re: ODBC DB Path

    Hi,

    If this question belongs to VB then you can try this

    Take the component - Microsoft ADO database control 6.0 on the form..
    right click on the control and select properties...
    in the General Tab, select 'Use Connection String' option..then
    Click the Build Button to follow the procedure...

    You can paste the connection string into the form directly and remove
    the control from the form...



    Praveen Jain
    [email protected]

  3. #3
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: ODBC DB Path

    If you use the MS Access database (MDB) you can parse the ODBC connect string for "...;DBQ=\YourDatabasePath\YourDatabaseFile.mdb;..." substring.
    Code:
    CDatabase db;
    db.Open("YourDSN");
    CString s = db.GetConnect();
    s.Find("DBQ=");
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  4. #4
    Join Date
    Jun 2003
    Location
    India
    Posts
    29

    Re: ODBC DB Path

    Hello All,

    Thanks for the reply, but what I'm looking at is to get the database path without establishing the connection.

    Thanks & Regards,
    Rajmathi
    Ms. Rajmathi

  5. #5
    Join Date
    May 2002
    Posts
    511

    Re: ODBC DB Path

    In dbcore.cpp the CDatabase::GetDatabaseName() method makes a call to the following ODBC API function.


    char szName[MAX_TNAME_LEN];
    SWORD nResult;
    RETCODE nRetCode;

    nRetCode = ::SQLGetInfo(m_hdbc, SQL_DATABASE_NAME, szName, _countof(szName), &nResult));

    In looking at this though this requires a connection also.

  6. #6
    Join Date
    May 2002
    Posts
    511

    Re: ODBC DB Path

    Perhaps from the DSN info itself?

    Code:
    	HENV hEnv;
    	UCHAR tmpDSN[256];
    	SWORD tmpDSNLen = 255;
    	SWORD ResultLen;
    	UCHAR tmpDriver[256];
    	SWORD tmpDriverLen = 255;
    	SWORD ResultDescLen;
    	RETCODE ReturnCode = SQL_SUCCESS;
    	int count = m_dateCTL.GetCount();
    	char tmpDate[10];
    
    	ReturnCode = ::SQLAllocEnv(&hEnv);
    	if (SQL_SUCCESS == ReturnCode)
    	{
    		ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_FIRST, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);
    
    		while (SQL_SUCCESS == ReturnCode)
    		{
                                                   // look at info
    
    			ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_NEXT, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);
    		}
    	}
    
    	::SQLFreeEnv(hEnv);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured