Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2002
    Posts
    8

    Unanswered: How to get Server Name? (Using VC++, MSSQL & ODBC)

    Hi. Is there a way in order to get the Server name using MSSQL ODBC in Visual C++? Here's my code:

    CString wstr_connect ;
    wstr_connect.Format( "DSN=%s;UID=%s;PWD=%s", gstr_DBName, gstr_UserID, gstr_Password ) ;
    CDatabase mydb ;
    BOOL ret = mydb.OpenEx( wstr_connect, CDatabase::noOdbcDialog ) ;
    CString info = mydb.GetConnect( ) ;

    GetConnect only returns the database name, user ID, password and WSID. How do i get the server name?

    Thanks in advance!

  2. #2
    Join Date
    Jul 2003
    Posts
    123
    I'm not using CDatabase at the moment, but check out this page:
    http://www.cppdoc.com/example/mfc/cl...CDatabase.html

    There is a function called GetConnectInfo(); maybe that can help you?

  3. #3
    Join Date
    Mar 2003
    Location
    California
    Posts
    20
    I think it depends on the driver you are using. I think one problem you are having is that you are not actually providing a "DBName"; your Format function has a string with "DSN=" which I am nearly certain means that you are using a datasource. The server is specified in the datasource.

    Note that the CDatabase class has a member m_hdbc; it can be used to get a handle for use with the SDK version of ODBC. Look at the sample code for CDatabase::m_hdbc; it might lead you to a good answer.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Maybe I'm missing something, but couldn't you just use:
    Code:
    SELECT @@servername
    -PatP

  5. #5
    Join Date
    Mar 2003
    Location
    California
    Posts
    20
    Quote Originally Posted by Pat Phelan
    Maybe I'm missing something, but couldn't you just use:
    Code:
    SELECT @@servername
    -PatP
    I don't know how to do that in VC; cwong asked how to do it "using MSSQL ODBC in Visual C++".

Posting Permissions

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