问题
I would like to offer a database connection prompt to the user. I can build my own, but it would be nice if I can use something that somebody else has already built (maybe something built into Windows or a free library available on the Internet). Anybody know how to do this in .Net?
EDIT: I found this and thought it was interesting: Showing a Connection String prompt in a WinForm application. This only works for SQL Server connections though.
回答1:
You might want to try using SQL Server Management Objects. This MSDN article has a good sample for prompting and connecting to a SQL server.
回答2:
ADO.NET has the handy ConnectionStringBuilder which will construct and validate a connection string. This would at least take the grunt work out of one part, allowing you to create a simple dialog box for the input.
回答3:
Microsoft has released the source code for the data connection dialog on Code Gallery.
Here is an blog post from Yaohai with more info and here is the home of Data Connection Dialog on Code Gallery.
回答4:
I combined the PropertyGrid Class with the SqlConnectionStringBuilder Class in a separate dialog and that worked really well for me.
回答5:
The only "built in" connection string functionality that I could think of is the one that comes up when you run a CMD script (essentially a batch file) that runs SQL scripts. However I'm not sure if it's something built into Visual Studio.
It's really simple to make one anyway. If you don't want the user to be able to input a straight-out connection string, you can put together one made up of four textboxes and a checkbox:
- Server
- Catalog Name
- checkbox for integrated security or SQL Authentication
- Username
- Password
Fairly trivial, IMHO.
来源:https://stackoverflow.com/questions/53178/prompt-for-database-connection-string