0

I developed a Windows based Application*(C# and SQL Server 2005)* in which I used a Connection Form which estabilish a connection between my application and SQL Server. I created a setup of my application. I installed it to Client Machine, after get installed I run the application first time, the Connection Form appears to estabilish a connection with SQL Server. I entered the required input for connection, the connection has estabilished. Whenever I closed the application the connection get totally closed. Now I have to reconnect with SQL Server to run the software once again.

My query is that, I want to connect my application with SQL Server only once untill it get uninstalled, by which I will not have to estabilish a connection repeatedly. The Connection Form should appear only once untill uninstallation. Thanks in advance to help me.

4

2 回答 2

2

通常应用程序从配置文件中读取它们的连接信息。您可能会做的只是让应用程序在用户输入后将您的连接字符串信息存储到文件中。

然后从那时起,当应用程序开始从您的文件中读取连接字符串时。

为您的连接字符串使用配置文件的示例位于:http ://www.dreamincode.net/forums/topic/31314-sql-basics-in-c%23/

于 2013-01-11T19:27:15.517 回答
1

从您的描述中,听起来您想保存连接字符串(而不是无限期地保持连接打开),这样您就可以在应用程序的后续启动时使用连接字符串,而不必在每次应用程序启动时都显示连接表单。

有多种考虑和方法可以实现这一目标。我将首先查看以下讨论存储和检索连接字符串的 MSDN 文章。

您可能还需要考虑从配置文件中读取连接字符串,尝试进行身份验证,如果失败,则显示连接表单,以便用户可以提供不同的凭据或在其环境发生变化时更改服务器\数据库名称。

于 2013-01-11T19:27:22.707 回答