OleDB连接字符串出错

时间:2014-10-07 10:17:09

标签: asp.net vb.net oledb oledbconnection oledbcommand

我正在使用OleDB连接到Accdb文件。但它显示错误

异常详细信息:System.ArgumentException:不支持关键字:'provider'。

来源错误:

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

我不知道为什么它仍然显示错误显示关键字未被支持:'提供商'

我的网站配置

   <connectionStrings>
    <add name="PPAPConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\ACCESS2013\TS16949_Linker.accdb" 
    providerName=".NET Framework Data Provider for OLE DB"/>
    </connectionStrings>

代码

Dim constr As String = ConfigurationManager.ConnectionStrings("PPAPConnectionString").ConnectionString
 Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
Dim qry As String
qry = "Select * from pfd_op_type where id=" & GridView1.SelectedDataKey.ToString
Dim con As System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbCommand
con = New System.Data.OleDb.OleDbConnection(constr)
cmd = New System.Data.OleDb.OleDbCommand(qry, con)
Dim da As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(cmd)
Dim dt As DataTable
dt = New DataTable
da.Fill(dt)
typ_code_Num.Text = dt.Rows(0)(0).ToString
Op_Typ_Name.Text = dt.Rows(0)(1).ToString

End Sub

[ArgumentException: Keyword not supported: 'provider'.]
   System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +5384504
   System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +95
   System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +59
   System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
   System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +167
   System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) +61
   System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +66
   System.Web.UI.WebControls.SqlDataSource.CreateConnection(String connectionString) +34
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +113
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974



--------------------------------------------------------------------------------

0 个答案:

没有答案