在App_Data中建立好Sql数据库后,应在web.config文档中加入connectionstring,将数据库连接信息添加,以便以后调用和更改。
在web.config中增加连接字符串:
//WebConfig中的位置 <connectionStrings> <add name="connectionString" connectionString="Data Source =192.168.1.1 ;Initial Catalog= RemoteControl;uid=sa;pwd=sa"/> </connectionStrings>
调用代码:
using System.Configuration;//命名空间 string strServer = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;//获取连接字符串
远程连接可以讲IP地址修改,当然推荐用Web Service 代替远程连接,更安全点。
远程连接可以看下面这篇文章:
http://www.cnblogs.com/zhangronghua/archive/2007/09/19/898048.html