I have an application which connects to a sql server database thru a SQL
Server ODBC driver. In the application, I have a database componenet with
its aliasname name set to the name of the ODBC driver. I have several
databses on the server and I need to know if I can get the actual name of
the database I am connecting to?Sam,
Try:
SELECT DB_NAME()
HTH
Jerry
"Sam" <Sam@.discussions.microsoft.com> wrote in message
news:F29D0818-2376-432D-B8AE-F8A734A8199F@.microsoft.com...
>I have an application which connects to a sql server database thru a SQL
> Server ODBC driver. In the application, I have a database componenet
> with
> its aliasname name set to the name of the ODBC driver. I have several
> databses on the server and I need to know if I can get the actual name of
> the database I am connecting to?|||SELECT DB_NAME()
David Portas
SQL Server MVP
--
"Sam" <Sam@.discussions.microsoft.com> wrote in message
news:F29D0818-2376-432D-B8AE-F8A734A8199F@.microsoft.com...
>I have an application which connects to a sql server database thru a SQL
> Server ODBC driver. In the application, I have a database componenet
> with
> its aliasname name set to the name of the ODBC driver. I have several
> databses on the server and I need to know if I can get the actual name of
> the database I am connecting to?|||Try:
select db_name()
go
AMB
"Sam" wrote:
> I have an application which connects to a sql server database thru a SQL
> Server ODBC driver. In the application, I have a database componenet wit
h
> its aliasname name set to the name of the ODBC driver. I have several
> databses on the server and I need to know if I can get the actual name of
> the database I am connecting to?|||Thanks :)
"David Portas" wrote:
> SELECT DB_NAME()
> --
> David Portas
> SQL Server MVP
> --
> "Sam" <Sam@.discussions.microsoft.com> wrote in message
> news:F29D0818-2376-432D-B8AE-F8A734A8199F@.microsoft.com...
>
>
Showing posts with label odbc. Show all posts
Showing posts with label odbc. Show all posts
Monday, March 26, 2012
Monday, March 19, 2012
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!I'm not using CDatabase at the moment, but check out this page:
http://www.cppdoc.com/example/mfc/classdoc/MFC/CDatabase.html
There is a function called GetConnectInfo(); maybe that can help you?|||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.|||Maybe I'm missing something, but couldn't you just use:SELECT @.@.servername-PatP|||Maybe I'm missing something, but couldn't you just use:SELECT @.@.servername-PatPI don't know how to do that in VC; cwong asked how to do it "using MSSQL ODBC in Visual C++".
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!I'm not using CDatabase at the moment, but check out this page:
http://www.cppdoc.com/example/mfc/classdoc/MFC/CDatabase.html
There is a function called GetConnectInfo(); maybe that can help you?|||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.|||Maybe I'm missing something, but couldn't you just use:SELECT @.@.servername-PatP|||Maybe I'm missing something, but couldn't you just use:SELECT @.@.servername-PatPI don't know how to do that in VC; cwong asked how to do it "using MSSQL ODBC in Visual C++".
Wednesday, March 7, 2012
How to get ODBC working with MSDE
Hi,
yes thanks .. but I did figure that out by myself.
SQLServer is running, I am able to osql on it ...
but ODBC refuses connectivity.
Maybe I just forgot something else.
>please have a look at
>http://support.microsoft.com/default...&Product=sql2k
You could checkout if your network protocols are on or not. OSQL may be
using shared memory connection here so it may be working properly.
KB article http://support.microsoft.com/?id=827204
yes thanks .. but I did figure that out by myself.
SQLServer is running, I am able to osql on it ...
but ODBC refuses connectivity.
Maybe I just forgot something else.
>please have a look at
>http://support.microsoft.com/default...&Product=sql2k
You could checkout if your network protocols are on or not. OSQL may be
using shared memory connection here so it may be working properly.
KB article http://support.microsoft.com/?id=827204
Subscribe to:
Posts (Atom)