Showing a Connection String prompt in a WinForm application
来源:百度文库 编辑:神马文学网 时间:2024/05/02 16:43:05
When I was putting together theData Dictionary Creator program, I needed to allow users to input a connection string. A lot of winform applications that require data connections give you a textbox and tell you to figure it out yourself, but I really wanted to show a prompt that let you test your connections, select databases on a server, etc.
I was surprised that I couldn‘t find a nice, free, winform control to build a connection string. I found somethingon CodeProject with a smart solution - it pops up the standard Data Link Properties dialog. The code mostly worked, but had some problems (passwords were lost if user didn‘t check "Allow Saving Password", problems with integrated security). I found some general suggestions in the comments and newsgroup postings and threw in some exception handling, and came up with something that worked pretty well for me. It‘s a little trickier than it looks, since setting certain properties in just the right order shifts the dialog into modes which hide tabs and stuff.
This requires references to a few COM objects:
%PROGRAMFILES%\Microsoft.NET\Primary Interop Assemblies\adodb.dll
%PROGRAMFILES%\Common Files\System\Ole DB\OLEDB32.DLL
I foundan article about using CreateObject or GetTypeByProgID to avoid the interop references, I think I‘d rather ship the interop stubs than worry about dynamic object calls failing when I‘m shipping an application, but it‘s interesting.
The next step for this would be bundle this up in a user control (textbox with an ellipses button to launch the dialog, maybe a balloon tip to show connection errors), but I‘m not sure I‘ll get to that any time soon. Here‘s the code as a simple function that pops the dialog and returns the selected connection string:
///
Showing a Connection String prompt in a WinForm application
Creating a Simple Web Application in NetBeans...
C Q&A: Displaying a JPG in your MFC Application
A Research on the Application of CALL in English langage teaching
Put a Flex UI On Your Application
Q & A in Travel
A career in audit
In a canyon
in town without a car
a flash in the pan
45.In a Strange City
A Rescue in China, Uncensored
A Rescue in China, Uncensored
Managing Employees in a Downturn
Infrastructure Ports in a storm
A Walk in the Woods
《In A Dream 梦幻》专辑
A Fairy Tale in Fall
A Rescue in China, Uncensored
Memorize a List in Order
Quixote: a Python-Centric Web Application Framework | Linux Journal
A Research on the Application of English langage teaching
Q & A: WebSphere Application Server 常见安全性问题 -...
Calling a DLL C++ function or class from a VC++ application