我的连接字符串visualstudio 2012 C#asp.net出现问题。示例:
公共分部类Search_Report:System.Web.UI.Page{
OleDbConnection conn = new OleDbConnection("Data Source=orcl;User ID=hr;Password=hr;Unicode=True");
void select()
{
//select statement into DataTable
try
{
conn.Open();
DataTable DtTabledaily = new DataTable();
string sql = "SELECT * FROM MAGANGMAYORA where rekening_no = '5300303139'";
OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn);
oda.Fill(DtTabledaily);
GridView1.DataSource = DtTabledaily;
GridView1.DataBind();
oda.Dispose();
conn.Close();
}
catch (System.Data.SqlClient.SqlException ex)
{
lblerror.Text = ex.Message;
}
但当运行程序时,我得到错误:An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'.
所以,我把我的conn改成:
OleDbConnection conn = new OleDbConnection("Provider=sqloledb;Data Source=orcl;User ID=hr;Password=hr;Unicode=True");
我再次运行程序,但在conn.Open();
中遇到另一个错误错误显示:
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
Invalid connection string attribute.
在我的Web.Config连接字符串中:
<connectionStrings>
<add name="ConnectionString1" connectionString="Data Source=orcl;User ID=hr;Password=hr;Unicode=True"
providerName="System.Data.OracleClient" />
</connectionStrings>
有人帮我。我不知道如何修复conn.Open()中的这个错误;谢谢
我将Oledb更改为OracleConnection,它解决了我的问题。谢谢你的建议。