473,563 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ODBC Prompt

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
4 3738
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
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.goo gle.com...
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
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 SQLDriverConnec t 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_PROM PT = 2

Dim Buf As New System.Text.Str ingBuilder

Retcode = SQLDriverConnec t(SQL_NULL_HDBC , _
Me.Handle.ToInt 32, _
"", _
SQL_NTS, _
Buf(255), _
MAXBUFLEN, _
1024, _
SQL_DRIVER_PROM PT)
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.goo gle.com...
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
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 SQLDriverConnec t 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(By Val sender As System.Object, ByVal e As
System.EventArg s) 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_PROM PT = 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(hEn v) = SQL_SUCCESS Then
If SQLAllocConnect (hEnv, hDBC) = SQL_SUCCESS Then

If SQLDriverConnec t(hDBC, Me.Handle.ToInt 32, constr, Len(constr), _
Buf, MAXBUFLEN, outlen, SQL_DRIVER_PROM PT) = SQL_SUCCESS Then

MsgBox(Buf)
Retcode = SQLDisconnect(h DBC)

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2215
by: Chetan | last post by:
I have setup an ODBC driver for my MySQL database and use a 3rd party program to connect to it. Everytime the software connects, the ODBC driver setup screen pops up. I have to click OK on it to continue. I set the parameter "Dont prompt on connect" in the options but this has not solved the issue. The system setup is Win2K SP2, MySQL...
2
2812
by: Abram | last post by:
I have an ODBC 3.0 Application on Windows NT Server maintaining a connection to a SQL Server 2000 database on the same machine. When an error occurs, I'd like to be able to determine whether the error is serious enough that the database connection has been lost, so I can have the application try to reconnect automatically. My understanding is...
0
1354
by: Me | last post by:
Hi all, Each new login to the PC, all the ODBC links to the SQL Server tables fail with the error "Connection failed" SQL Server Error 10061 Connection Open (connect()) Connection failed:
0
580
by: Henry C. Wu | last post by:
I tried the link: http://support.microsoft.com/?id=193128 to prompt the ODBC Data Source dialog box, but the syntax ".Properties("Prompt") = adPromptAlways" rendered an error stating that it is only a "READONLY" property. Any clues on how to prompt the ODBC Data source dialog box and return the connection string after the user has selected...
2
74651
by: SKB | last post by:
Hi, I am absolutely new to this area. I am getting the following difficulty : Access denied for user 'ODBC'@'localhost' (using password: NO) when I try the mysql command from within the C:\Program Files\MySQL\MySQL Server 5.0\bin on the command window. Please note that the MySQL is runnging as I have tried the command NET START MySQL and it...
2
9376
by: 111mike | last post by:
Hello, Here's my problem. I cannot connect to mysql database using odbc string connections or dns. I keep getting a "cannot connect to mysql server localhost." I'm running windows XP Pro and have installed IIS as my server. I have installed Mysql 5.0 and mysql ODBC driver 3.51.12 in their default locations. Database is up and running...
3
3629
by: enjoylife27 | last post by:
Hi there, I am using Perl 5.8 with Apache 2.2 on Win XP SP2, all configured and working fine. I am able to run perl programs from command prompt. I am also able to call CGI scripts from HTML pages using Apache and it works fine. The problem is with the database connectivity using WIN32::ODBC. Look at the following code: my $DSN = "ABC";...
2
2059
by: pg36476 | last post by:
Has anybody managed to get the OS authentication to work with Microsoft ODBC driver for Oracle? I have link tables in MS Access database that are linked to an Oracle database. ODBC connection has been set up using the microsoft ODBC administrator, and UID is "/" and PWD is "" is set in the registry. But when opening the link table in Access, a...
9
10200
by: Bob Sanderson | last post by:
I'm trying to export a table to an ODBC database using a VBA subroutine. I have tested the ODBC setup manually and it works fine but when I try to do it with VBA, I get a "connection failed" error. This is the code I'm using. Can anyone tell me what is wrong with it? DoCmd.TransferDatabase acExport, "ODBC Database",...
0
7659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3634
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.