所有页面硬编码的连接具有中有一个ConnectionString的一个webconfig文件...我怎么不stringin
但后来当过我访问数据库,我不得不一次又一次地写相同的ConnectionString ..有没有一种方法可以从webconfig文件本身获取连接字符串的值..?
System.Data.SqlClient.SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString =
@"Data Source=JAGMIT-PC\SQLEXPRESS;Initial Catalog=SumooHAgentDB;Integrated Security=True";
System.Data.SqlClient.SqlCommand dataCommand = new SqlCommand();
dataCommand.Connection = dataConnection;
有什么建议?
确保你添加引用System.Configuration在此之前这个。 – 2009-10-13 21:53:37
并确保将你的更新(因为它没有被使用,可以过时)连接字符串里面/配置/ connectionStrings配置单元,在你的web.config – 2009-10-13 21:57:44
所以在这个即时硬编码数据源= JAGMIT-PC \ SQLEXPRESS;初始目录= SumooHAgentDB;集成安全性= True取代NameofConnectionstring? – user175084 2009-10-13 21:58:17