asp.net中MySQL的连接字符串是什么

时间:2014-08-21 13:50:44

标签: c# mysql asp.net asp.net-mvc-4

我在asp.net中编写了一个控制器,用于从mysql DB中检索数据。运行时显示错误,即

 Source Error: 

Line 7:    <configSections>
Line 8:      <!-- For more information on Entity Framework configuration, visit    
http://go.microsoft.com/fwlink/?LinkID=237468 -->
Line 9:      <section name="MySQLRoleProvider"  
type="MySql.Web.Security.MySQLRoleProvider,   
MySql.Web, Version=5.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" 
connectionStringName="YourconnectionstringName" applicationName="LoginControl" />
Line 10:   </configSections>
Line 11:   <connectionStrings>

我的web.config文件正在关注

 <?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit 
http://go.microsoft.com/fwlink/?LinkID=237468 -->

<section name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, 
MySql.Web, Version=5.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"  
connectionStringName="YourconnectionstringName" applicationName="LoginControl" />

</configSections>
<connectionStrings>
<remove name="LocalMySqlServer"/>
<add name="LocalMySqlServer" 
 connectionString="server=localhost:3306;uid=root;pwd=;database=test;"/>
</connectionStrings>


< appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages>
  <namespaces>
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Optimization" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.WebPages" />
  </namespaces>
 </pages>
 </system.web>
 <system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <modules runAllManagedModulesForAllRequests="true" />
 <  handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." 
  verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" 
  scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" 
  preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." 
  verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" 
  scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" 
  preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*."
 verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
 type="System.Web.Handlers.TransferRequestHandler" 
 preCondition="integratedMode,runtimeVersionv4.0" />
 </handlers>
 </system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory  
type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="v11.0" />
  </parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>

然后我不知道如何使用此文件连接mysql DB。因为我尝试了很多方法,但我无法做到。

请任何人帮忙

1 个答案:

答案 0 :(得分:1)

great resource有连接字符串可以帮助您。