views:

675

answers:

5

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.

+13  A: 

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.

Gulzar
A: 

I am trying to prompt the user for a connection string so they can connect to a database like the prompt you get when you open Query Analyzer (for Sql Server). I would prefer to not use a textbox for the connection string, but I will if I have to or if the prompt is too complicated (it's a development tool, so it's not that big of a deal).

Brian
Yup. It is a common requirement. Please check my post.
Gulzar
+2  A: 

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.

FlySwat
A: 

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.

Jon Limjap
A: 

I combined the PropertyGrid Class with the SqlConnectionStringBuilder Class in a separate dialog and that worked really well for me.

jan
Good idea. I may try that.
John Saunders