1

I'm trying to retrieve information on username from active connection (SQL Server Express) in MapInfo 11.5 32bit. First I tried using Server_ConnectInfo( ConnectionNo, SRV_CONNECT_INFO_SQL_USER_ID ) which should return "String result, returning the name of the SQL user ID." (by MapBasic Reference), but it returns "dbo" (my DB schema). Then I tried Server_GetODBCHConn() function. In MapBasic Reference this example stands:

'********************************************************************
'* Find the identity of the Connected database
DECLARE FUNCTION SQLGetInfo LIB "ODBC32.DLL" (BYVAL odbchdbc AS INTEGER, 
BYVAL infoflag AS INTEGER, val AS STRING, 
BYVAL len AS INTEGER, outlen AS INTEGER) AS INTEGER

Dim rc, outlen, hdbc, odbchdbc AS INTEGER
Dim DBName AS STRING

' Connect to a database
hdbc = Server_Connect("ODBC", "DLG=1")
odbchdbc = Server_GetodbcHConn(hdbc) ' get ODBC connection handle

' Get database name from ODBC
DBName = STRING$(33, "0") ' Initialize output buffer
rc = SQLGetInfo(odbchdbc, 17 , DBName, 40, outlen) ' get ODBC Database Name

' Display results (database name)
if rc <> 0 THEN
Note "SQLGetInfo Error rc=" + rc + ", outlen=" + outlen
    else
Note "Connected to Database: " + DBName
    end if

'********************************************************************

According to https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetinfo-function syntax for SQLGetInfo is:

SQLRETURN SQLGetInfo(
SQLHDBC ConnectionHandle,
SQLUSMALLINT InfoType,
SQLPOINTER InfoValuePtr,
SQLSMALLINT BufferLength,
SQLSMALLINT * StringLengthPtr);

So, in line rc = SQLGetInfo(odbchdbc, 17 , DBName, 40, outlen) parameter "17" represents type of information we are requiring, but I can't find out what number represents username (SQL_USER_NAME stands as one of possible InfoType values, but no number is linked to this function). I have tried every number 1-60 but none of them returned username.

closed as off-topic by Ian Turton Aug 4 '17 at 9:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • I'm not sure how this is off-topic. My problem is specifically linked to MapBasic. SQL can accept (is accepting) InputType by its name (eg. SQL_USER_NAME), however this is not the case in MapBasic, it requires specific ID (which I cant find anywhere). – Kevin Malone Aug 4 '17 at 12:25
  • It is clearly on-topic. Iant just don't know what he is doing. – Uffe Kousgaard Aug 4 '17 at 12:29
  • I think this is OK result. Actually "dbo" string returned here is not a schema - it is a user that has implied permissions to perform all activities in the database (that is you logged in probably as "sa" or another user which has all permisions on that database). Try to create another user which has typical user rights and test it again. – sys49152 Aug 6 '17 at 8:40
  • @ sys49152. You are right! For all others I'm getting their usernames correctly, and mine is "dbo". Thank you – Kevin Malone Aug 8 '17 at 9:28