求助,ADO数据库连接
namespace Accessdatabase{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//web.config配置文件取出数据库连接串
string sqlconnstr=ConfigurationManager.ConnectionStrings ["ConnectionString"].ConnectionString;
//建立数据库连接对象
SqlConnection sqlconn = new SqlConnection(sqlconnstr);
//打开连接对象
sqlconn.Open();
Label1 .Text ="成功建立Sql Server 2005 数据库连接";
//关闭连接对象
sqlconn.Close();
sqlconn=null;
}
}
}
web.config
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\Mydatabase.mdf;Integrated Security=Ture;User Instance=Ture"/>
</connectionStrings>
运行提示出错
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
项“integrated security”的值无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentException: 项“integrated security”的值无效。
源错误:
行 22: string sqlconnstr=ConfigurationManager.ConnectionStrings ["ConnectionString"].ConnectionString;
行 23: //建立数据库连接对象
行 24: SqlConnection sqlconn = new SqlConnection(sqlconnstr);
行 25: //打开连接对象
行 26: sqlconn.Open();
源文件: F:\\Accessdatabase\Accessdatabase\connection.aspx.cs 行: 24
堆栈跟踪:
[ArgumentException: 项“integrated security”的值无效。]
System.(String stringValue) +1484539
System.() +1484544
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +89
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +125
System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +56
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4
System.Data.SqlClient.SqlConnection..ctor(String connectionString) +21
Accessdatabase._Default.Page_Load(Object sender, EventArgs e) in F:\\Accessdatabase\Accessdatabase\connection.aspx.cs:24
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.1433; 版本:2.0.50727.1433