问题
Is there a way to display the connection properties dialog for connection string browsing(for database) in run time?
As I want the user to be able to connect to various database using the GUI. The same one as we get in visual studio connection properties dialog.
Thanks in Advance
回答1:
Look for this article explaining exactly what are you looking for. What she say is the following:
You will need to add a couple references to your project:
- OLE DB Service Component 1.0 Type Library
- Microsoft ActiveX Data Objects 2.x Library
Use the following code:
using MSDASC; using ADODB; private string BuildConnectionString() { string strConnString = ""; object _con = null; MSDASC.DataLinks _link = new MSDASC.DataLinks(); _con = _link.PromptNew(); if (_con == null) return string.Empty; strConnString = ((ADODB.Connection)_con).ConnectionString; return strConnString; }
回答2:
I was looking for exactly that, and it appears that Microsoft has published the source for the Visual Studio connection dialog, so that it can be used outside VS :
I just tried it, it works fine :)
Update 7/2019
Since the Microsoft Code site is dark, and there doesn't seem to be an official Microsoft posting for Data Connection Dialog
, here is a link to a Github user repository with the Microsoft code.
https://github.com/kjbartel/ConnectionDialog
Original but now dead link http://code.msdn.microsoft.com/Connection
回答3:
It's quite old, but there's this article - might have some inspiration for you.
回答4:
I don't know if there exists a 'predefined' form for it, but, you could offcourse create your own form, and use one the DbConnectionStringBuilder classes (SqlConnectionStringBuilder, OracleConnectionStringBuilder, OleDbConnectionStringBuilder) to create the connectionstring from the parameters the user entered on your custom created form.
回答5:
You can also use Universal Data Link Files
http://msdn.microsoft.com/en-us/library/e38h511e%28VS.71%29.aspx
Work with XP but I never tried it in Vista or Seven
回答6:
There is also http://www.codeproject.com/KB/dialog/UDL_Net.aspx and this commercial one www.mjmeans.com/dcd.aspx.
来源:https://stackoverflow.com/questions/2205993/winforms-connection-properties-dialog-for-configuration-string