开发者

Error in data-binding database to web form

i am a beginner in making website, i learned things at msdn only, but now when i try to make a very simple Website, i am having this error

"Unable to find the requested .Net Framework Data Provider. It may not be installed."

http://i.stack.imgur.com/RV5qY.jpg

steps followed to create the web site > New WebSite>Empty Website>Add new WebForm>Dragged The GridView on the page >Added new data source(sdf format).

The test query runs fine, but when i try to run the webPage, i am having this error, i have spent the whole previous day searching for a solution(but they seem to be valid no more, or are for older versions). I am using Vs2010 ultimate, got sqlServer compact edition 2008 SP2 installed. Here is the Web.config file :

<configuration>
  <connectionStrings>
 <add name="ConnectionString" connectionString="Data Source=C:\Users\TarunG\Documents\Visual Studio 2010\WebSi开发者_运维问答tes\WebSite1\App_Data\Database1.sdf"
  providerName="System.Data.SqlServerCe.Client.3.5" />
 </connectionStrings>
  <system.web>
  <compilation debug="true" targetFramework="4.0"></compilation>
  </system.web>
  </configuration>

The database contains only one Table - Result1. The default.aspx file :

<body>
  <form id="form1" runat="server">
  <div>
    </div>
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataKeyNames="Roll No." DataSourceID="SqlDataSource1">
    <Columns>
<asp:BoundField DataField="Roll No." HeaderText="Roll No." ReadOnly="True"
        SortExpression="Roll No." />
      <asp:BoundField DataField="Category" HeaderText="Category"
        SortExpression="Category" />
      <asp:BoundField DataField="Rank" HeaderText="Rank" SortExpression="Rank" />
      <asp:BoundField DataField="Registration No." HeaderText="Registration No."
        SortExpression="Registration No." />
      <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
    </Columns>
  </asp:GridView>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
    SelectCommand="SELECT * FROM [Result1]"></asp:SqlDataSource>
  </form>
</body>

machine.config :

<add name="SQL Server Compact Edition Data Provider" invariant="System.Data.SqlServerCe" description=".NET Framework Data Provider for Microsoft SQL Server Compact Edition" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
   <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
      <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>


For a web site, you should be using SQL Server Express, not SQL Server Compact Edition. SQL Server Compact Edition is designed for standalone, single-user scenarios. ASP.NET is looking for the SQL Server Express drivers and not finding them.

I suggest uninstalling SQL Server Compact Edition, then installing SQL Server Express from here: http://www.microsoft.com/express/Database/ That will also install the necessary drivers.

With SS Express installed, make your web.config connection string look like this:

<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|Database1.sdf;Integrated Security=True;User Instance=True" providerName="Microsoft.Sql.Client.3.5" />

Good luck!


as mentioned here: http://msdn.microsoft.com/en-us/library/ms247257.aspx, your Connection String should be something like:

Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|Database1.sdf;Integrated Security=True;User Instance=True

btw, you need SQL Server Express for the above line to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜