dbTalk Databases Forums  

odbc version info hard to find

comp.databases.postgresql comp.databases.postgresql


Discuss odbc version info hard to find in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Joe Stateson
 
Posts: n/a

Default odbc version info hard to find - 11-05-2007 , 03:13 PM






I wish to put the version numbers of various drivers in an about box for my
web app. I can easily find the sql server version from a connection:

OdbcConnection oc = new
OdbcConnection(WebConfigurationManager.ConnectionS trings["acqlibdbConnectionString"].ToString());
oc.Open();
string strVersion = oc.ServerVersion; // 8.1.8 is shown for our Postgre
acqlib


However, there is no version for the odbc driver. I was expecting to see
8.02.0400 somewhere so I can see what version the Microsoft IIS has
installed.

I then tried enumerating the drivers starting with "SQL Server" and looping
thru each one ...

iResult = ODBC_GetDSNs.SQLDataSources(
lhEnv, SQL_FETCH_NEXT,
sDSNItem, 1024,
ref iDSNLen, sDRVItem,
1024, ref iDRVLen)l

The driver for PostgreSQLAcqlib eventually shows up as "PostgreSQL ANSI" but
there is no version number in the sDRVItem aggregate. I know I am using
"PostgreSQL ANSI" and I would like to directly find out what the version #
is and it seems this is not easily available. I did spot the name
"psqlodbc.dll" in my "oc" connection, but the actual name of the dll is
"psqlodbc30a.dll"


--
================================================== ====================
Joseph "Beemer Biker" Stateson
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
================================================== ====================


Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: odbc version info hard to find - 11-06-2007 , 03:00 AM






In comp.databases.postgresql Joe Stateson <jstateson (AT) swri (DOT) edu> wrote:
Quote:
I wish to put the version numbers of various drivers in an about box for my
web app. I can easily find the sql server version from a connection:

[...]

However, there is no version for the odbc driver. I was expecting to see
8.02.0400 somewhere so I can see what version the Microsoft IIS has
installed.
I don't know about ODBC, but browsing the source of psqlODBC I see that
the driver version should be returned when you call SQLGetInfo
with SQL_DRIVER_VER (= 7) as second argument.

Does that help?

Yours,
Laurenz Albe


Reply With Quote
  #3  
Old   
Joe Stateson
 
Posts: n/a

Default Re: odbc version info hard to find - 11-07-2007 , 03:06 PM



"Laurenz Albe" <invite (AT) spam (DOT) to.invalid> wrote

Quote:
In comp.databases.postgresql Joe Stateson <jstateson (AT) swri (DOT) edu> wrote:
I wish to put the version numbers of various drivers in an about box for
my
web app. I can easily find the sql server version from a connection:

[...]

However, there is no version for the odbc driver. I was expecting to see
8.02.0400 somewhere so I can see what version the Microsoft IIS has
installed.

I don't know about ODBC, but browsing the source of psqlODBC I see that
the driver version should be returned when you call SQLGetInfo
with SQL_DRIVER_VER (= 7) as second argument.

Does that help?

Yours,
Laurenz Albe
Thanks Laurenz, but it only returned the name of the driver.




Reply With Quote
  #4  
Old   
Joe Stateson
 
Posts: n/a

Default Re: odbc version info hard to find - 11-08-2007 , 09:53 AM



"Rainer Bauer" <usenet (AT) munnin (DOT) com> wrote

Quote:
Joe Stateson schrieb:

"Laurenz Albe" <invite (AT) spam (DOT) to.invalid> wrote in message
news:1194339619.839843 (AT) proxy (DOT) dienste.wien.at...
In comp.databases.postgresql Joe Stateson <jstateson (AT) swri (DOT) edu> wrote:
I wish to put the version numbers of various drivers in an about box
for
my
web app. I can easily find the sql server version from a connection:

[...]

However, there is no version for the odbc driver. I was expecting to
see
8.02.0400 somewhere so I can see what version the Microsoft IIS has
installed.

I don't know about ODBC, but browsing the source of psqlODBC I see that
the driver version should be returned when you call SQLGetInfo
with SQL_DRIVER_VER (= 7) as second argument.

Does that help?

Yours,
Laurenz Albe

Thanks Laurenz, but it only returned the name of the driver.

What version are you using? This call returns "08.02.0402" on my machine:
SQLGetInfo( &sqlRV, hDBC, SQL_DRIVER_VER, SQLPOINTER(pBuf), sizeof(pBuf),
&nSize )

Rainer
Thanks Laurenz and Rainer. It turned out that my call to SQLGetInfo failed
(returning a -1) and the contents of the string was unchanged from a
previous call where I asked for the name of the driver and the call
succeeded. This code is not easy to write as I cannot include "sql.h" nor
"sqlext.h" in my C# code and have to guess as how to code them. So far I
have been able to allocate an environment handle, then set the ODBC
attribute to "200" and version to "3" then allocate a DBC handle and ask for
the driver version. I am getting an error code at that point and when I get
more time I will go back and debug it.

[DllImport("odbc32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLSetEnvAttr(IntPtr envHandle,
ushort attribute, IntPtr val, int stringLength);

[DllImport("odbc32.dll")]
public static extern short SQLAllocHandle(
short HandleType, IntPtr InputHandle,
out IntPtr OutputHandle);

[DllImport("odbc32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLGetInfo(IntPtr envHandle, ushort
attribute, StringBuilder inConnection, short stringLength,
out short stringLength2Ptr);


iResult = ODBC_Alloc.SQLAllocHandle(ODBC_Alloc.SQL_HANDLE_EN V,
hEnvIn, out lhEnv);
iResult = ODBC_GetDSNs.SQLSetEnvAttr(lhEnv, SQL_ATTR_ODBC_VERSION,
(IntPtr)SQL_OV_ODBC3, 0);
iResult = ODBC_Alloc.SQLAllocHandle(ODBC_Alloc.SQL_HANDLE_DB C,
lhEnv, out hDbc);
iResult = ODBC_GetDSNs.SQLGetInfo(hDbc, SQL_DRIVER_VER,
outConnection, DEFAULT_RESULT_SIZE, out stringLength2Ptr);

The very last one gives a -1 for iResult. AFAICT the 3 calls above the
GetInfo are required.


--
================================================== ====================
Joseph "Beemer Biker" Stateson
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
================================================== ====================



Reply With Quote
  #5  
Old   
Joe Stateson
 
Posts: n/a

Default Re: odbc version info hard to find - 11-08-2007 , 01:34 PM



"Rainer Bauer" <usenet (AT) munnin (DOT) com> wrote

Quote:
Joe Stateson wrote:

This code is not easy to write as I cannot include "sql.h" nor
"sqlext.h" in my C# code and have to guess as how to code them.

Mmh, couldn't you simple use
Microsoft.Data.Odbc.OdbcConnection.GetInfo(), or
is that method private?
That is how I got the server version. It easily shows up in that
connection.

AFAICT there is no GetInfo method in System.Data.Odbc.OdbcConnection.
Neither intellisense nor the debugger show that method. Setting a
breakpoint before and after "oc.Open();" I do see some info that seems odd:

ProviderInfo shows "" for DriverVersion but "8.2.4" for ServerVersion. We
just upgraded our server from 8.1 to 8.2. There is a new .05.00 driver out
but I am still using 8.02.04.00 and it is a coincidence that the driver
version matches the server version as two days ago 8.1.2 (or whatever) was
in ServerVersion (the last time I looked).

It also shows that the boolean IsV3Driver is false. The XP odbc manager
shows I am using PSQLODBC30A.DLL even though the ProviderInfo class shows
_driverName to be just "PSQLODBC.DLL" A search of my drive shows no file
with that name exists. Windows explorer shows that psqlodbc30a.dll to be
Version "08.02.0400" and the same for that dll's Product Version.

I do not know the significence of the IsV3Driver being false. The C# call
iResult = ODBC_GetDSNs.SQLSetEnvAttr(lhEnv, 200, (IntPtr)3, 0) returns
success so I assume I have a V3 driver.

My web app is also using Npgsql DotNet components and setting a breakpoint
after
npgsqlConnection.Open() shows
"PostgreSqlVersion {8.2.4}" and
"ServerVersion "8.2.4" "
However, Npgsql is only a component and is not as useful as a true ODBC
driver and I am changing out all my npgsqlCommands to OdbcCommands. It is
nice that npgsql is a dll that can be distributed with the web project but I
was able to talk our admin into installing posgresql odbc drivers on our IIs
server and he let me put ajax on also.




--
================================================== ====================
Joseph "Beemer Biker" Stateson
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
================================================== ====================



Reply With Quote
  #6  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: odbc version info hard to find - 11-09-2007 , 04:25 AM



Joe Stateson <jstateson (AT) swri (DOT) edu> wrote:
Quote:
I wish to put the version numbers of various drivers in an about box
for my web app.

I don't know about ODBC, but browsing the source of psqlODBC I see that
the driver version should be returned when you call SQLGetInfo
with SQL_DRIVER_VER (= 7) as second argument.

Thanks Laurenz and Rainer. It turned out that my call to SQLGetInfo
failed [...]
So far I
have been able to allocate an environment handle, then set the ODBC
attribute to "200" and version to "3" then allocate a DBC handle and
ask for the driver version. I am getting an error code at that point
and when I get more time I will go back and debug it.
Ok, I tried it out myself, and I find that you must connect before you can
retrieve the driver version with SQLGetInfo().

The documentation from Microsoft states that

"All calls to SQLGetInfo require an open connection, except when the
InfoType is SQL_ODBC_VER, which returns the version of the Driver Manager."

Yours,
Laurenz Albe


Reply With Quote
  #7  
Old   
Joe Stateson
 
Posts: n/a

Default Re :solved-odbc version info - 11-09-2007 , 11:20 AM




"Laurenz Albe" <invite (AT) spam (DOT) to.invalid> wrote

Quote:
Joe Stateson <jstateson (AT) swri (DOT) edu> wrote:
I wish to put the version numbers of various drivers in an about box
for my web app.

I don't know about ODBC, but browsing the source of psqlODBC I see
that
the driver version should be returned when you call SQLGetInfo
with SQL_DRIVER_VER (= 7) as second argument.

Thanks Laurenz and Rainer. It turned out that my call to SQLGetInfo
failed [...]
So far I
have been able to allocate an environment handle, then set the ODBC
attribute to "200" and version to "3" then allocate a DBC handle and
ask for the driver version. I am getting an error code at that point
and when I get more time I will go back and debug it.

Ok, I tried it out myself, and I find that you must connect before you can
retrieve the driver version with SQLGetInfo().

The documentation from Microsoft states that

"All calls to SQLGetInfo require an open connection, except when the
InfoType is SQL_ODBC_VER, which returns the version of the Driver
Manager."

Yours,
Laurenz Albe
Thanks Laurenz, I left out the connect

iResult = ODBC_GetDSNs.SQLConnect(hDbc, sdsn, (short)sdsn.Length, suid,
(short)suid.Length, spwd, (short)spwd.Length);
"DriverConnect" did not work, it had to be "Connect" and it seems the only
arguement required is the DSN and even the lengths of the strings are
ignored.

Using SQL_ODBC_VER got me back 3.52.0000 and, as you mentioned, a connection
was not necessary. I am not sure what the 3.52 applies to.

Using SQL_DRIVER_VER got me back 08.02.0500 (i upgraded to the .05 odbc
driver this morning to make sure the version string was not the server
version. I also noticed that the boolean IsV3Driver is now true when
opening Microsoft's OdbcConnection where as yesterday with 8.2.4 it was
false.

I plan on extracting the name of the server from the odbc connection manager
as my web app must access various subdirectories on the server and currently
they are hard coded.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.