连接数据库时出现问题 [英] problem in connect to database
本文介绍了连接数据库时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Data;
使用 System.Data.SqlClient;
使用 System.Configuration;
命名空间 DAL
{
public class Class1
{
string connStr = ConfigurationManager.ConnectionStrings [ myCon]。ToString();
}
}
withal在'web.config'中我有:
< add name = myCon connectionString = Data Source = mydata; Initial Catalog = myDB; Integrated Security = false; User Id = sa; Password = 123 providerName = System.Data.SqlClient / >
任何帮助都会有所帮助
解决案
重启VSTS。
参考: - http://social.msdn.microsoft.com/Forums/windows/en-US / 82fcd001-243f-4604-bec4-02de92c4f568 / problem-with-configurationmanager-class?forum = winformsapplications [ ^ ]
这可能会有所帮助。
你刚添加了命名空间system.configuration这是不够的。
你还要添加对程序集的引用System.Configuration.dll,右键单击References选项卡,选择add reference,然后找到System.Configuration。
你必须使用SYS tem.Configuration你需要添加引用
System.Configuration.dll
并替换
string connStr = ConfigurationManager.ConnectionStrings [ myCon]。ToString();
with
string connStr = ConfigurationManager.ConnectionStrings [ myCon]。ConnectionString
如果有帮助请告诉我
hi . in DAL i have the below code . the error is "the name 'configurationManager' does not exist in current context".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace DAL
{
public class Class1
{
string connStr = ConfigurationManager.ConnectionStrings["myCon"].ToString();
}
}
withal in 'web.config' i have:
<add name="myCon" connectionString="Data Source=mydata;Initial Catalog=myDB;Integrated Security=false; User Id=sa; Password=123" providerName="System.Data.SqlClient" />
any help would be appreciate
解决方案
Restart the VSTS.
Refer:-http://social.msdn.microsoft.com/Forums/windows/en-US/82fcd001-243f-4604-bec4-02de92c4f568/problem-with-the-configurationmanager-class?forum=winformsapplications[^]
This may help.
you just have added namespace system.configuration which is not enough.
You have also to add the reference to the assembly System.Configuration.dll , by right-click-ing on the References tab, choose add reference and then find System.Configuration.
U have to useSystem.Configurationnamespace for that u have to add reference
System.Configuration.dll
and replace the
string connStr = ConfigurationManager.ConnectionStrings["myCon"].ToString();
with
string connStr = ConfigurationManager.ConnectionStrings["myCon"].ConnectionString
and let me know if its helps or not
这篇关于连接数据库时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文