虚心求教:连接数据库出错的问题......
在Web.config中的配置如下:
<configuration>
<appSettings>
<add key= "ConnectionString " value= "server=6AAB8F3DF4F44C3;database=Audi100;User id=user;pwd=user; "/>
<add key= "DBConnectionString " value= "Provide=SQLOLEDB;Data Source=6AAB8F3DF4F44C3;Initial Catalog=Audi100;User id=user;pwd=user;Trusted_Connection=yes; "/>
</appSettings>
运行后有错误提示说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆
栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentException: 在ConnectionString 中未指定 OLE DB 提供程序。示例为:“Provider=SQLOLEDB;”。
源错误:
行 157:// open DB Connection via OleDb
行 158:Connection = new OleDbConnection(sConnectionString);
行 159:Connection.Open();
源文件: c:\inetpub\wwwroot\audi100\ccutility.cs 行:158
堆栈跟踪:
[ArgumentException: 在 ConnectionString 中未指定 OLE DB
提供程序。示例为:“Provider=SQLOLEDB;”。]
System.Data.OleDb.OleDbConnectionString.ValidateParse()
System.Data.Common.DBConnectionString..ctor(String
connectionString, UdlSupport checkForUdl)
System.Data.OleDb.OleDbConnectionString..ctor(String
connectionString)
System.Data.OleDb.OleDbConnectionString.ParseString
(String connectionString)
System.Data.OleDb.OleDbConnection.set_ConnectionString
(String value)
System.Data.OleDb.OleDbConnection..ctor(String
connectionString)
Audi100.CCUtility.DBOpen() in
c:\inetpub\wwwroot\audi100\ccutility.cs:158
Audi100.CCUtility..ctor(Object parent) in
c:\inetpub\wwwroot\audi100\ccutility.cs:89
Audi100.technic.Page_Load(Object sender, EventArgs e)
in c:\inetpub\wwwroot\audi100\technic.aspx.cs:45
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
[解决办法]
提示为连接字符串有误
[解决办法]
连接SQL,没有 Provide=SQLOLEDB 这种写法
[解决办法]
<connectionStrings>
<add name= "ConnectionString " connectionString= "server=192.168.0.1;database=Northwind;uid=sa;password=sa "/>
</connectionStrings>
[解决办法]
<appSettings>
<!--
connStr参数设置,事例说明:
(1)Sql server数据库,例如“server=local;database=test;uid=sa;pwd=;”
(2)Access数据库,例如 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|WebSeven.mdb "
-->
<add key= "connStr " value= "server=127.0.0.1;database=DbName;uid=sa;pwd=; " />
</appSettings>
[解决办法]
SQLServer示例如下:
<appSettings>
<add key= "Server " value= " "/>
<add key= "DataBase " value= " "/>
<add key= "UID " value= " "/>
<add key= "PSW " value= " "/>
</appSettings>
[解决办法]
<add key= "Server " value= "服务器名 "/>
<add key= "DataBase " value= "数据库名 "/>
<add key= "UID " value= "用户名 "/>
<add key= "PSW " value= "密码 "/>
[解决办法]
connectionstring写错了! 是Provider 不是Provide