2013-01-06 4 views
3

이 오류가 발생했습니다.지원되지 않는 키워드 : 'provider'

키워드가 지원되지 않습니다 : 'provider'.

설명 현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 발생했습니다. 오류 및 코드에서 시작된 위치에 대한 자세한 정보는 스택 추적을 검토하십시오.

예외 정보 : System.ArgumentException : 키워드가 지원되지 않습니다 : 'provider'.

소스 오류 :

Line 24:  { 
Line 25:   Session["id"] = e.CommandArgument.ToString(); 
Line 26:   SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 
Line 27:   con.Open(); 
Line 28:    SqlCommand cmd1 = new SqlCommand("INSERT INTO tb2 (id, name) SELECT id, name FROM tb1 where id='"+Session["id"].ToString()+"'", con); 

Source File: c:\inetpub\wwwroot\logon\page.aspx Line: 26 

여기 내 전체 코드입니다 :

<%@ Page Language="C#" Debug="true" %> 
<%@ Import Namespace="System" %> 
<%@ Import Namespace="System.Data" %> 
<%@ Import Namespace = "System.Data.SqlClient" %> 

<script runat="server" type="css"> 

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     bind(); 
    } 
} 
protected void bind() 
{ 
    PendingRecordsGridview.DataSourceID = ""; 
    PendingRecordsGridview.DataSource = sd1; 
    PendingRecordsGridview.DataBind(); 
} 
protected void PendingRecordsGridview_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "accept") 
    { 
     Session["id"] = e.CommandArgument.ToString(); 
     SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 
      con.Open(); 
      SqlCommand cmd1 = new SqlCommand("INSERT INTO tb2 (id, name) SELECT id, name FROM tb1 where id='"+Session["id"].ToString()+"'", con); 
      SqlCommand cmd2 = new SqlCommand("delete from tb1 where id='"+Session["id"].ToString()+"'", con); 
      cmd1.ExecuteNonQuery(); 
      cmd2.ExecuteNonQuery(); 
      bind(); 
    } 
} 
</script> 
<form id="form1" runat="server"> 
<asp:GridView ID="PendingRecordsGridview" runat="server" AutoGenerateColumns="False" DataKeyNames="id" onrowcommand="PendingRecordsGridview_RowCommand" DataSourceID="sd1"> 
     <Columns> 
      <asp:templatefield HeaderText="Accept"> 
       <ItemTemplate> 
        <asp:Button CommandArgument='<%# Bind("id") %>' ID="Button1" runat="server" CausesValidation="false" CommandName="accept" Text="Accept" /> 
       </ItemTemplate> 
      </asp:templatefield> 
      <asp:templatefield HeaderText="name" SortExpression="name"> 
       <EditItemTemplate> 
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("name") %>'> 
        </asp:TextBox> 
       </EditItemTemplate> 
       <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("name") %>'> 
        </asp:Label> 
       </ItemTemplate> 
      </asp:templatefield> 
      <asp:templatefield HeaderText="id" SortExpression="id"> 
       <EditItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'> 
        </asp:Label> 
       </EditItemTemplate> 
       <ItemTemplate> 
        <asp:Label ID="Label2" runat="server" Text='<%# Bind("id") %>'> 
        </asp:Label> 
       </ItemTemplate> 
      </asp:templatefield> 
     </Columns> 
    </asp:GridView> 
    <asp:SqlDataSource ID="sd1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
     ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
     SelectCommand="SELECT * FROM [tb1]" DeleteCommand="DELETE FROM [tb1] WHERE [id] = ?" InsertCommand="INSERT INTO [tb1] ([name]) VALUES (?)" UpdateCommand="UPDATE [tb1] SET [name] = ? WHERE [id] = ?"> 
     <DeleteParameters> 
      <asp:parameter Name="id" Type="Int32" /> 
     </DeleteParameters> 
     <UpdateParameters> 
      <asp:parameter Name="name" Type="String" /> 
      <asp:parameter Name="id" Type="Int32" /> 
     </UpdateParameters> 
     <InsertParameters> 
      <asp:parameter Name="name" Type="String" /> 
     </InsertParameters> 
</asp:SqlDataSource> 
</form>  

의 Web.config

<configuration> 
    <connectionStrings> 

     <add name="ConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\inetpub\wwwroot\logon\_private\db1.mdb" 
      providerName="System.Data.OleDb" /> 
    </connectionStrings> 
</configuration> 

도와주세요은! 고맙습니다!

+0

연결 문자열이있는 web.config의 일부를 표시 할 수 있습니까? – scartag

+3

이와 같은 문자열 연결을 사용하면 코드가 [SQL Injection] (http://en.wikipedia.org/wiki/SQL_injection)에 열려 있습니다. – Oded

+0

@scartag 이것이 모두 내 코드입니다. web.config를 사용하지 않습니다. Visual Studio 나 Visual Basic이 아닌 표현식 웹을 사용하고 있습니다. –

답변

2

SQL Server 연결 개체를 사용하여 Access 데이터베이스에 액세스하려는 것 같습니다. (연결 구성은 Jet 데이터베이스 엔진을 참조합니다.)

대신 OleDbConnection (및 관련 OleDbCommand 등)을 사용해야합니다. 연결 문자열에 대한 자세한 내용은

볼 : 코멘트에 언급 한 바와 같이 http://connectionstrings.com/access

그리고, 코드는 SQL 주입 공격에 succeptable입니다. how to protect yourself from SQL Injection Attacks을 읽을 수도 있습니다 (이 기사는 SQL Server 용이지만 많은 개념이 Access에도 적용됩니다)

관련 문제