提示输入数据库连接字符串
我想向用户提供数据库连接提示。 我可以构建自己的,但如果我可以使用其他人已经构建的东西(可能是 Windows 中内置的东西或 Internet 上提供的免费库),那就太好了。 有人知道如何在.Net 中做到这一点吗?
编辑:我发现了这个并认为它很有趣:在 WinForm 应用程序中显示连接字符串提示。 但这仅适用于 SQL Server 连接。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我将 PropertyGrid 类 与 < a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx" rel="nofollow noreferrer">SqlConnectionStringBuilder 类 在单独的对话框中,并且 < a href="https://stackoverflow.com/questions/1103637/usercontrol-to-connect-to-a-sqlserver-database">对我来说效果非常好。
I combined the PropertyGrid Class with the SqlConnectionStringBuilder Class in a separate dialog and that worked really well for me.
我能想到的唯一“内置”连接字符串功能是当您运行运行 SQL 脚本的 CMD 脚本(本质上是批处理文件)时出现的功能。 但是我不确定它是否是 Visual Studio 中内置的东西。
无论如何,制作一个非常简单。 如果您不希望用户能够输入直接的连接字符串,您可以将由四个文本框和一个复选框组成的一个组合在一起:
相当简单,恕我直言。
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:
Fairly trivial, IMHO.
Microsoft 已在 Code Gallery 上发布了数据连接对话框的源代码。
这是一个 来自瑶海的博客文章,其中包含更多信息,这里是主页代码库上的数据连接对话框。
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.
ADO.NET 有方便的 ConnectionStringBuilder,它可以构造和验证连接字符串。 这至少可以消除一个部分的繁重工作,允许您为输入创建一个简单的对话框。
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.
您可能想尝试使用SQL Server 管理对象。 这篇 MSDN 文章提供了一个很好的提示和连接到 SQL 服务器的示例。
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.