2016-02-27 124 views
1

我正在使用Microsoft Visual Studio 2015(Community Edition)構建一個簡單的c#web應用程序(而不是MVC)。我的數據庫是MySQL的最新版本,就像我安裝的MySQL連接器一樣。C#MySQL簡單會員供應商

我已經修改了我的Web.config文件以使用WebMatrix Simple Membership Provider和MySQL。

這裏是我的Web.config文件:

<?xml version="1.0" encoding="utf-8"?> 
    <configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core"> 
     <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" /> 
     <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" /> 
     <section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" /> 
     <section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" /> 
    </sectionGroup> 
    </configSections> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5.2"> 
     <assemblies> 
     <add assembly="MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D" /> 
     <add assembly="MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D" /> 
     </assemblies> 
    </compilation> 
    <httpRuntime targetFramework="4.5.2" /> 
    <membership defaultProvider="SimpleMembershipProvider"> 
     <providers> 
     <clear /> 
     <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" /> 
     </providers> 
    </membership> 
    <profile defaultProvider="MySQLProfileProvider"> 
     <providers> 
     <remove name="MySQLProfileProvider" /> 
     <add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" applicationName="/" /> 
     </providers> 
    </profile> 
    <roleManager enabled="true" defaultProvider="SimpleRoleProvider"> 
     <providers> 
     <clear/> 
     <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" /> 
     </providers> 
    </roleManager> 
    <machineKey validationKey="AutoGenerate" validation="SHA1"/> 
    <siteMap defaultProvider="MySqlSiteMapProvider"> 
     <providers> 
     <remove name="MySqlSiteMapProvider" /> 
     <add name="MySqlSiteMapProvider" type="MySql.Web.SiteMap.MySqlSiteMapProvider, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" applicationName="/" /> 
     </providers> 
    </siteMap> 
    <webParts> 
     <personalization defaultProvider="MySQLPersonalizationProvider"> 
     <providers> 
      <remove name="MySQLPersonalizationProvider" /> 
      <add name="MySQLPersonalizationProvider" type="MySql.Web.Personalization.MySqlPersonalizationProvider, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" applicationName="/" /> 
     </providers> 
     </personalization> 
    </webParts> 
    <sessionState mode="InProc" customProvider="DefaultSessionProvider"> 
     <providers> 
     <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" /> 
     </providers> 
    </sessionState> 
    <customErrors mode="Off" /> 
    <trust level="Full" /> 
    </system.web> 
    <connectionStrings> 
    <remove name="LocalMySqlServer"/> 
    <add name="RP" connectionString="Server=localhost; Database=my_db; uid=my_uid; pwd=my_password;" providerName="MySql.Data.MySqlClient"/> 
    </connectionStrings> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    <!-- This prevents the Windows Event Log from frequently logging that HMAC1 is being used (when the other party needs it). --> 
    <legacyHMACWarning enabled="0" /> 
    <!-- When targeting ASP.NET MVC 3, this assemblyBinding makes MVC 1 and 2 references relink 
     to MVC 3 so libraries such as DotNetOpenAuth that compile against MVC 1 will work with it. 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    --> 
    </runtime> 
    <system.data> 
    <DbProviderFactories> 
     <remove invariant="MySql.Data.MySqlClient" /> 
     <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.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> 
    </DbProviderFactories> 
    </system.data> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> 
    </providers> 
    </entityFramework> 
    <system.net> 
    <defaultProxy enabled="true" /> 
    <settings> 
     <!-- This setting causes .NET to check certificate revocation lists (CRL) 
      before trusting HTTPS certificates. But this setting tends to not 
      be allowed in shared hosting environments. --> 
     <!--<servicePointManager checkCertificateRevocationList="true"/>--> 
    </settings> 
    </system.net> 
    <dotNetOpenAuth> 
    <messaging> 
     <untrustedWebRequest> 
     <whitelistHosts> 
      <!-- Uncomment to enable communication with localhost (should generally not activate in production!) --> 
      <!--<add name="localhost" />--> 
     </whitelistHosts> 
     </untrustedWebRequest> 
    </messaging> 
    <!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. --> 
    <reporting enabled="true" /> 
    <!-- This is an optional configuration section where aspects of dotnetopenauth can be customized. --> 
    <!-- For a complete set of configuration options see http://www.dotnetopenauth.net/developers/code-snippets/configuration-options/ --> 
    <openid> 
     <relyingParty> 
     <security requireSsl="false"> 
      <!-- Uncomment the trustedProviders tag if your relying party should only accept positive assertions from a closed set of OpenID Providers. --> 
      <!--<trustedProviders rejectAssertionsFromUntrustedProviders="true"> 
      <add endpoint="https://www.google.com/accounts/o8/ud" /> 
      </trustedProviders>--> 
     </security> 
     <behaviors> 
      <!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible 
       with OPs that use Attribute Exchange (in various formats). --> 
      <add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth.OpenId.RelyingParty" /> 
     </behaviors> 
     </relyingParty> 
    </openid> 
    </dotNetOpenAuth> 
    <uri> 
    <!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names), 
     which is necessary for OpenID urls with unicode characters in the domain/host name. 
     It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. --> 
    <idn enabled="All" /> 
    <iriParsing enabled="true" /> 
    </uri> 
</configuration> 

簡單的成員提供被設置爲自動創建會員數據庫表,它成功地做到了。

我可以從我的數據庫中選擇數據並顯示。

但是,當我去註冊一個用戶(使用簡單成員提供程序自動創建的網頁)時,出現錯誤。

通過關聯的簡單提供程序,成員資料數據被默認寫入兩個表,一個userprofile表和一個webpages_membership表。

當我點擊「提交」按鈕數據被正確地寫入USERPROFILE表,但寫入數據時的webpages_membership表我得到這個錯誤:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[UserId] FROM [UserProfile] WHERE (UPPER([Email]) = UPPER('[email protected]')' at line 1 

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: MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[UserId] FROM [UserProfile] WHERE (UPPER([Email]) = UPPER('[email protected]')' at line 1 

Source Error: 


Line 50:     { 
Line 51:      bool requireEmailConfirmation = !WebMail.SmtpServer.IsEmpty(); 
Line 52:      var token = WebSecurity.CreateAccount(email, password, requireEmailConfirmation); 
Line 53:      if (requireEmailConfirmation) 
Line 54:      { 

Source File: c:\Users\brian\OneDrive\Documents\Visual Studio 2015\Projects\Robey's Pub VS2015 Razor\Account\Register.cshtml Line: 52 

Stack Trace: 


[MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[UserId] FROM [UserProfile] WHERE (UPPER([Email]) = UPPER('[email protected]')' at line 1] 
    MySql.Data.MySqlClient.MySqlStream.ReadPacket() +272 
    MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) +68 
    MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId) +17 
    MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +110 
    MySql.Data.MySqlClient.MySqlDataReader.NextResult() +783 
    MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +1564 
    MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar() +112 
    WebMatrix.Data.Database.QueryValue(String commandText, Object[] args) +98 
    WebMatrix.WebData.DatabaseWrapper.QueryValue(String commandText, Object[] parameters) +29 
    WebMatrix.WebData.SimpleMembershipProvider.GetUserId(IDatabase db, String userTableName, String userNameColumn, String userIdColumn, SimpleMembershipProviderCasingBehavior casingBehavior, String userName) +217 
    WebMatrix.WebData.SimpleMembershipProvider.CreateAccount(String userName, String password, Boolean requireConfirmationToken) +158 
    WebMatrix.WebData.WebSecurity.CreateAccount(String userName, String password, Boolean requireConfirmationToken) +51 
    ASP._Page_Account_Register_cshtml.Execute() in c:\Users\brian\OneDrive\Documents\Visual Studio 2015\Projects\Robey's Pub VS2015 Razor\Account\Register.cshtml:52 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +177 
    System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +83 
    System.Web.WebPages.WebPage.ExecutePageHierarchy() +103 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +101 
    System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +110 

我無法弄清楚如何解決這個問題。任何幫助讚賞。謝謝!


更多信息;

在該語句的程序錯誤(這是一個自動(計算機)生成的語句,通過簡單成員資格提供創建:

VAR令牌= WebSecurity.CreateAccount(電子郵件,密碼,requireEmailConfirmation);

下面是錯誤的詳細信息:


MySql.Data.MySqlClient.MySqlException was unhandled by user code ErrorCode=-2147467259 

的HResult = -2147467259
消息=你的SQL語法有錯誤;請檢查與您的MySQL服務器版本相對應的手冊,以便在第1行的[UserId] FROM [UserProfile] WHERE(UPPER([Email])= UPPER('[email protected]')')附近使用正確的語法。Number = 1064
源= MySql.Data

堆棧跟蹤: 在MySql.Data.MySqlClient.MySqlStream.ReadPacket() 在MySql.Data.MySqlClient.NativeDriver.GetResult(的Int32 & affectedRow,Int64的& insertedId) MySQL的.Data.MySqlClient.Driver.GetResult(Int32 statementId,Int32 & affectedRows,Int64 & insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId,Boolean force) 在MySql.Data.MySqlClient.MySqlDataReader.NextResult() 在MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(的CommandBehavior行爲) 在MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar() 在WebMatrix.Data.Database.QueryValue (String commandText,Object [] args) at WebMatrix。WebData.DatabaseWrapper.QueryValue(字符串的CommandText,對象[]參數) 在WebMatrix.WebData.SimpleMembershipProvider.GetUserId(分貝了IDatabase,字符串userTableName,字符串userNameColumn,字符串userIdColumn,SimpleMembershipProviderCasingBehavior casingBehavior,字符串username) 在WebMatrix.WebData.SimpleMembershipProvider。 CreateAccount(String userName,String password,Boolean requireConfirmationToken) at WebMatrix.WebData.WebSecurity.CreateAccount(String userName,String password,Boolean requireConfirmationToken)在ASP.Page_Account_Register_cshtml.Execute \ Visual Studio 2015 \ Projects \ Robey's Pub VS2015 Razor \ Account \ Register.cshtml:line 52 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePage層次結構(IEnumerable`1執行人) 在System.Web.WebPages.WebPage.ExecutePageHierarchy() 在System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext的pageContext,TextWriter的作家,WebPageRenderingBase起始頁) 在System.Web.WebPages.WebPageHttpHandler .ProcessRequestInternal(HttpContextBase的HttpContext)

InnerException: 
+0

我更換的SQL Server的過程目前是無線在我的項目中,MySQL正在運行相同的問題。你能解決它嗎? – Joey

回答

0

你有錯誤在您的查詢 這裏請檢查您的查詢一次 '[用戶ID] FROM [用戶配置] WHERE(UPPER([郵件])= UPPER(' 布賴恩@ robeyspub .com')'

檢查您是否使用單行情如此

這 '[用戶ID] FROM [用戶配置] WHERE(UPPER([郵件])= UPPER(' 這將是第一個字符串 ,這將是第二 ')'

但什麼系統解釋 [email protected]

做一兩件事,使用調試器,並檢查您的查詢,並運行它到MySQL,你會得到什麼樣的錯誤你得到 感謝

+0

問題是...那不是「我的」查詢...該查詢是從與簡單成員資格提供程序相關聯的DLL派生的。我無法以任何方式更改查詢。 –

+0

很明顯,你的錯誤是在說 你的SQL語法錯誤;請查看與您的MySQL服務器版本相對應的手冊,以便在第1行的[UserId] FROM [UserProfile] WHERE(UPPER([Email])= UPPER('[email protected]')']附近使用正確的語法。] – 2016-02-27 01:51:44

+0

我有錯誤,但我不能發表評論,因爲它說在我的評論中有「太多字符」。 我不確定如何發佈我的錯誤... –