Web.config and MySQL Issues.

StephanM picture StephanM · Jan 26, 2012 · Viewed 9.8k times · Source

Long and short my machine had issues and I had to rebuild it. I reinstalled all my software and put my project backups back on the machine. I have been trying to solve SQL connect issues that I just can't get around.

So after going through many changes and error, I put the working production version back on my machine. When I run it I get the following error: Parser Error Message: Unknown database 'p10009307_sec'

The Database is known to my SQL Workbench and If I drop a Database connection on a page and configure it I can connect.

The Question is where is it looking that it can't find MySQL? I assume its in the Webconfig, but I don't see anything out of the ordinary that would make localhost diffrent. I made a copy of my webconfig with only the sections that refrence MySQL.

 `<connectionStrings>
<remove name="LocalMySqlServer" />
<add name="LocalMySqlServer" connectionString="server=localhost;password=xxxxxxxxxx;
User Id=xxxxxxxxxx;logging=True;database=xxxxxxxxxx_sec" providerName="MySql.Data.MySqlClient" />
<add name="'LocalSqlServer" connectionString="server=localhost;database=xxxxxxxxxx_CUS;
logging=True;password=xxxxxxxxxx;User Id=xxxxxxxxxxER" providerName="MySql.Data.MySqlClient" />

<remove name="LocalSqlServer" />
<add name="p10009307_cusConnectionString" connectionString="server=localhost;
User Id=xxxxxxxxxxER;password=xxxxxxxxxx;database=xxxxxxxxxx_CUS"
providerName="MySql.Data.MySqlClient" />
<add name="p10009307_cusConnectionString2" connectionString="server=localhost;
User Id=xxxxxxxxxER;password=xxxxxxxxxx;database=xxxxxxxxxx_CUS; 
SQL SERVER MODE=True" providerName="MySql.Data.MySqlClient" />

</connectionStrings>

<system.data>
   <DbProviderFactories>
     <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.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>
</system.data>
<system.web>
    <customErrors mode="Off" />
    <compilation targetFramework="4.0" debug="true">
    <assemblies>
        <add assembly="MySql.Data, Version=6.4.4.0, Culture=neutral,
        PublicKeyToken=c5687fc88969c44d" />
    </assemblies>
    </compilation>
    <authorization>
        <allow roles="Admin" />
    </authorization>
    <authentication mode="Forms">
       <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>
    <membership defaultProvider="MySQLMembershipProvider">
      <providers>
          <clear />
              <remove name="MySQLMembershipProvider" />
              <add name="MySQLMembershipProvider"
              type="MySql.Web.Security.MySQLMembershipProvider, 
              MySql.Web, Version=6.4.4.0, Culture=neutral, 
              PublicKeyToken=c5687fc88969c44d" applicationName="/" 
              description="Membership Provider" 
              connectionStringName="LocalMySqlServer" 
              writeExceptionsToEventLog="True" 
              autogenerateschema="True" 
              enablePasswordRetrieval="False" 
              enablePasswordReset="True" 
              requiresQuestionAndAnswer="False" 
              requiresUniqueEmail="False" passwordFormat="Clear" 
              maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7"
              minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10"
              passwordStrengthRegularExpression="" />
      </providers>
    </membership>
<profile defaultProvider="MySQLProfileProvider">
  <providers>
    <clear />
    <remove name="MySQLProfileProvider" />
    <add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, 
    MySql.Web, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
    applicationName="/" description="Profile provider" 
    connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="False"
    autogenerateschema="True" />
 </providers>
</profile>
<roleManager enabled="true" defaultProvider="MySQLRoleProvider">
  <providers>
    <clear />
    <remove name="MySQLRoleProvider" />
    <add applicationName="/" description="Role Provider" connectionStringName="LocalMySqlServer"
    writeExceptionsToEventLog="True" autogenerateschema="True" name="MySQLRoleProvider"
    type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.4.4.0, Culture=neutral,
    PublicKeyToken=c5687fc88969c44d" />
 </providers>
</roleManager>
<sessionState mode="Custom" cookieless="true" regenerateExpiredSessionId="true"
customProvider="MySqlSessionStateProvider">
<providers>
    <add name="MySqlSessionStateProvider" type="MySql.Web.SessionState.MySqlSessionStateStore,
    MySql.Web, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
    applicationName="/" description="State Provider" connectionStringName="LocalMySqlServer"
    writeExceptionsToEventLog="True" autogenerateschema="True" />
</providers>
</sessionState></system.web>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" />
    <bindingRedirect oldVersion="0.0.0.0-6.3.7.0" newVersion="6.4.4.0" />
  </dependentAssembly>
</assemblyBinding>
  </runtime>

</configuration>`

Everything is running local host at this point I have put the DLL's in the bin directory, I don't know what i am missing.

Answer

user191966 picture user191966 · Jan 26, 2012

I don't see anything in that config snippet that tells the "MySQL Data Provider" which one out of available conn-strings to use.

There's got to be something in the code that tells it either the conn-string name or the conn-string value. Something like this:

System.Configuration.ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString

Also, your 2nd conn-string has a single-quote character right before its name: 'LocalSqlServer

Perhaps you accidentally added it, and now the conn string cannot be found by the name of "LocalSqlServer" (if that's the one that's the problem, anyway).