![](/img/trans.png)
[英]C# Windows Form Application With SQL Server database deployment
[英]How to configure sql database c# windows form application
我目前正在用C#编写Windows窗体应用程序。
我正在使用Microsoft SQL Server Management 2008 R2将数据存储在数据库中。
当我使用自己的笔记本电脑时,我的应用程序工作正常,因为数据库中的服务器名称设置为localhost。
但是,如果我在其他人的笔记本电脑上尝试(无法连接到我的数据库),则该程序将无法工作。
我想为此程序编写一个配置文件,以便用户可以在任何地方访问我的Windows窗体应用程序。
我确信如何完成它。
我的服务器名称是localhost,这是Form1.cs中的SQL连接字符串。 帮助和示例参考,将不胜感激,谢谢
myConn = new SqlConnection("Server = localhost; Initial Catalog= dbName; Trusted_Connection = True");
更新 (我没有密码可以连接)
<connsectionStrings>
<add name="myConn" connectionString="Data Source=PC6\SA;Initial Catalog=dbName;"/>
</connsectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
试试这个代码
SQL Server身份验证
<add name="myConn" connectionString="Data Source=PC6\SA;Initial Catalog=dbName;User ID=sa;Password=sa123"/>
Windows验证
<add name="myConn" connectionString="Data Source=PC6\SA;Initial Catalog=dbName; />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.