By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,625 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,625 IT Pros & Developers. It's quick & easy.

ODBC Prompt

P: n/a
Hi I was wondering how can I program a button to make the ODBC dialog
box appear or prompt the user. And once the user has selected his/her
choice the connection string will be saved at a variable.

Thanks so much,
Henry :)
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Henry C. Wu wrote:
Hi I was wondering how can I program a button to make the ODBC dialog
box appear or prompt the user. And once the user has selected his/her
choice the connection string will be saved at a variable.

Thanks so much,
Henry :)


Find the name of the .cpl or .dll file that controls it and use shell
perhaps?

The ODBC settings are stored in the registry (IIRC) so you could just read
the properties from there.

--

I'll have a B please Bob.
Nov 21 '05 #2

P: n/a
If you want merely the user to select an existing ODBC data source, you can
build your own dialog showing a list using the SQLDataSources ODBC API
function:

http://msdn.microsoft.com/library/de...atasources.asp

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"Henry C. Wu" <he***********@gmail.com> escribió en el mensaje
news:44**************************@posting.google.c om...
Hi I was wondering how can I program a button to make the ODBC dialog
box appear or prompt the user. And once the user has selected his/her
choice the connection string will be saved at a variable.

Thanks so much,
Henry :)

Nov 21 '05 #3

P: n/a
Hi Carlos,
It'll be great if I can prompt the DSN or ODBC dialog box in where
the user can just click the DSN and return the value. I've already done
the other method,... it loops through all dsn & stores them at a
combobox,..but still Im curious on how can I prompt the dialog box. Any
clues?

Here's what I got so far,..but with errors :(
----------------
Public Declare Function SQLDriverConnect Lib "ODBC32.DLL" (ByVal hDBC
As Integer, ByVal hWnd As Short, ByVal constr As String, ByVal
constrlen As Short, ByVal buf As String, ByVal buflen As Short, ByRef
outlen As Short, ByVal prompt As Short) As Short
Dim Retcode As Short

Const SQL_NTS = -3 'Null-terminated string
Const SQL_NOSCAN = 2
Const SQL_NOSCAN_ON = 1
Const SQL_NULL_HENV = 0
Const SQL_NULL_HDBC = 0
Const SQL_NULL_HSTMT = 0
Const SQL_SUCCESS = 0
Const SQL_DROP = 1
Const MAXBUFLEN = 255

Const SQL_DRIVER_PROMPT = 2

Dim Buf As New System.Text.StringBuilder

Retcode = SQLDriverConnect(SQL_NULL_HDBC, _
Me.Handle.ToInt32, _
"", _
SQL_NTS, _
Buf(255), _
MAXBUFLEN, _
1024, _
SQL_DRIVER_PROMPT)
Debug.WriteLine(Buf)
-----------------------------

Thanks so much,
Henry :)
Carlos J. Quintero [.NET MVP] wrote:
If you want merely the user to select an existing ODBC data source, you can build your own dialog showing a list using the SQLDataSources ODBC API function:

http://msdn.microsoft.com/library/de...atasources.asp
--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"Henry C. Wu" <he***********@gmail.com> escribió en el mensaje
news:44**************************@posting.google.c om...
Hi I was wondering how can I program a button to make the ODBC dialog box appear or prompt the user. And once the user has selected his/her choice the connection string will be saved at a variable.

Thanks so much,
Henry :)


Nov 21 '05 #4

P: n/a
Hi Henry, there were several bugs in your code. This works for me:

Public Declare Function SQLAllocEnv Lib "odbc32.dll" (ByRef env As Integer)
As Short
Public Declare Function SQLAllocConnect Lib "odbc32.dll" (ByVal env As
Integer, ByRef lHdbc As Integer) As Short
Public Declare Function SQLDriverConnect Lib "ODBC32.DLL" (ByVal hDBC As
Integer, ByVal hWnd As Integer, ByVal constr As String, ByVal constrlen As
Short, ByVal buf As String, ByVal buflen As Short, ByRef outlen As Short,
ByVal prompt As Short) As Short
Public Declare Function SQLFreeConnect Lib "odbc32.dll" (ByVal lHdbc As
Integer) As Short
Public Declare Function SQLFreeEnv Lib "odbc32.dll" (ByVal env As Integer)
As Short
Public Declare Function SQLDisconnect Lib "odbc32.dll" (ByVal lHdbc As
Integer) As Short

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button.Click

Const SQL_NTS = -3 'Null-terminated string
Const SQL_NOSCAN = 2
Const SQL_NOSCAN_ON = 1
Const SQL_NULL_HENV = 0
Const SQL_NULL_HDBC = 0
Const SQL_NULL_HSTMT = 0
Const SQL_SUCCESS = 0
Const SQL_DROP = 1
Const MAXBUFLEN = 255

Const SQL_DRIVER_PROMPT = 2

Dim Buf As String = New String(" "c, MAXBUFLEN)
Dim constr As String = ""
Dim outlen As Short
Dim Retcode As Short
Dim hEnv As Integer
Dim hDBC As Integer

If SQLAllocEnv(hEnv) = SQL_SUCCESS Then
If SQLAllocConnect(hEnv, hDBC) = SQL_SUCCESS Then

If SQLDriverConnect(hDBC, Me.Handle.ToInt32, constr, Len(constr), _
Buf, MAXBUFLEN, outlen, SQL_DRIVER_PROMPT) = SQL_SUCCESS Then

MsgBox(Buf)
Retcode = SQLDisconnect(hDBC)

End If

Retcode = SQLFreeConnect(hDBC)

End If

Retcode = SQLFreeEnv(hEnv)

End If

End Sub

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.