2015-05-21 3 views
0

Итак, я пытаюсь изучить ASP.NET, но я застрял, когда дело доходит до соединений с БД.C# ASP.NET подключение к ошибке базы данных

я получаю следующее сообщение об ошибке:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.

и

Stack Trace:

[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1480903
WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(String connectionString) +63
WebMatrix.Data.<>c__DisplayClass15.b__14() +16
WebMatrix.Data.Database.get_Connection() +19
WebMatrix.Data.Database.EnsureConnectionOpen() +12
WebMatrix.Data.d__0.MoveNext() +66
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
WebMatrix.Data.Database.Query(String commandText, Object[] parameters) +102
ASP._Page_NewUser_cshtml.Execute() in c:\Users\Euaggelos\Documents\Visual Studio 2013\WebSites\WebSite5\NewUser.cshtml:20
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +199
System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
System.Web.WebPages.WebPage.ExecutePageHierarchy() +131
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +116

Проблема заключается в том, что у меня есть .net Framework Поставщик данных установлен.

Вот часть моего кода:

<connectionStrings> 
    <add name="DB1Entities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\DB1Entities.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 

@using WebMatrix.Data; 

@{ 
    Page.Title = "Add you user"; 
    Layout = "_Layout.cshtml"; 
    var db = Database.Open("DB1Entities"); 
    var selectQueryString = "SELECT * FROM Users ORDER BY FirstName"; 
} 



<h1>New user</h1> 

<table> 
    <tr> 
     <th>Id</th> 
     <th>First name</th> 
     <th>Last name</th> 
    </tr> 
    @foreach (var row in db.Query(selectQueryString)) <!--THIS IS THE ERROR LINE--> 
    { 
     <tr> 
      <td>@row.Id</td> 
      <td>@row.FirstName</td> 
      <td>@row.LastName</td> 
     </tr> 
    } 
</table> 

enter image description here

+0

UNKOWN ну, может быть попытка восстановления или удаления может также помочь в использовании ASP.NET, когда MVC - это путь вперед. – Enzero

+0

Я ремонтировал его несколько раз, с перезапуском между ними и ничего не произошло. Если бы вы могли предоставить хороший учебник MVC, я буду более чем счастлив проверить его. –

+0

есть хороший курс в [multipalsight] (http://www.pluralsight.com/courses/asp-dotnet-5-first-look), хотя есть и другие доступные курсы. [ASP.NET 5: First Look ] (http://www.pluralsight.com/courses/asp-dotnet-5-first-look) – Enzero

ответ

0

Вам может понадобиться, чтобы добавить это в файл app.config

<system.data> 
<DbProviderFactories> 
    <remove invariant="System.Data.SqlServerCe.4.0" /> 
    <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> 
</DbProviderFactories> 

+0

Ничего не изменилось –

0

Ваша строка соединения для первого проекта базы данных Entity Framework. Однако, похоже, вы не используете EF на своем сайте WebMatrix. Вы используете стандартный SQL для запроса базы данных. Измените строку подключения к простому одному:

<connectionStrings> 
    <add name="DB1Entities" connectionString="data source=LocalDB)\v11.0;attachdbfilename=|DataDirectory|\DB1Entities.mdf;integrated security=True;" providerName="System.Data.SqlClient" /> 
</connectionStrings> 

Если вы хотите использовать Entity Framework с проектом Web-страницы, вы должны использовать код Первый подход, как подробно описано в моей статье здесь: http://www.mikesdotnetting.com/article/182/entity-framework-code-first-development-with-webmatrix

Смежные вопросы