title: Can't connect with Database.Open("MySQLConnection") - The server was not found or was not accessible
body: <p>I'm trying to make chart/graph in ASP.NET in Visual Studio based on results in the database and I'm having problems with connecting to database with <code>Database.Open().</code> 
  I'm getting error: </p>
  
  <blockquote>
    <p>SqlException (0x80131904): A network-related or instance-specific
    error occurred while establishing a connection to SQL Server. The
    server was not found or was not accessible. Verify that the instance
    name is correct and that SQL Server is configured to allow remote
    connections. (provider: Named Pipes Provider, error: 40 - Could not
    open a connection to SQL Server)</p>
  </blockquote>
  
  <p>I'm using MySQL and the database is online (even though I tried with local db and I'm  getting the same error)</p>
  
  <p>I found this kind of creating graphs here:  <a href="http://www.asp.net/web-pages/overview/data/7-displaying-data-in-a-chart" rel="nofollow">http://www.asp.net/web-pages/overview/data/7-displaying-data-in-a-chart</a></p>
  
  <p>This is the code in .cshtml</p>
  
  <pre><code>@using WebMatrix.Data;
  @{
      var db = Database.Open("MySQLConnection");
      var data = db.Query("SELECT user_IP, user_Country FROM user_stats");
      var myChart = new Chart(width: 600, height: 400)
          .AddTitle("Naslov")
          .DataBindTable(dataSource: data, xField: "userIP")
          .Write();
  }
  </code></pre>
  
  <p>Here is connection string I'm using in <code>Web.config</code> (I removed real username and password here)</p>
  
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name="MySQLConnection"
       connectionString="Server=46.105.103.40;Database=miranzab_webtrafficanalyzer;Uid=username;Pwd=password;"
       providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>P.S. I've read about this kind of exceptions and usually there's a problem with connection string, but I'm using that same connection string without any problems for connecting to databse in other parts of application (In Models and Controllers) and it works fine...though I'm using this for connecting:</p>
  
  <pre><code>cWebTrafficDb checkUserStatsWrapper = new cWebTrafficDb();  //this class is for opening and closing connections
  checkUserStatsWrapper.cmd.CommandText = string.Format("select * from user_stats where user_ip = '{0}'", userIp);
  MySqlDataReader reader = checkUserStatsWrapper.cmd.ExecuteReader();
  </code></pre>
  
  <p>P.S.S I am using MySql and I've changed provider name as few users said it might be the problem... The error was the same.</p>
  
  <p>toddmo thank you very much. this finally got to the connection string. but now I'm having problems with it too lol...I was getting error like <code>System.ArgumentException: Keyword not supported: 'server'</code>. and the same for 'database' property in connection string and then I googled for error and it seems that I had to change connection string to this <code>&lt;add name="MySQLConnection" connectionString="Data Source=46.105.103.40;Initial Catalog=miranzab_webtrafficanalyzer;Integrated Security=SSPI;User Id=username;Password=password" providerName="MySql.Data.MySqlClient" /&gt;</code></p>
  
  <p>Here is the whole Web.config file: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=301880
    --&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;
   
   &lt;connectionStrings&gt;
      &lt;add name="MySQLConnection"
        connectionString="Data Source=46.105.103.40;Initial Catalog=miranzab_webtrafficanalyzer;Integrated Security=SSPI;User Id=username;Password=password;"
           providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
      
    &lt;system.web&gt;
      &lt;authentication mode="None" /&gt;
      &lt;compilation debug="true" targetFramework="4.5.2" /&gt;
      &lt;httpRuntime targetFramework="4.5.2" /&gt;
      &lt;customErrors mode="Off" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules&gt;
        &lt;remove name="FormsAuthentication" /&gt;
      &lt;/modules&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="mssqllocaldb" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
    &lt;system.codedom&gt;
      &lt;compilers&gt;
        &lt;compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /&gt;
        &lt;compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&amp;quot;Web\&amp;quot; /optionInfer+" /&gt;
      &lt;/compilers&gt;
    &lt;/system.codedom&gt;
  &lt;/configuration&gt;</code></pre>
  </div>
  </div>
  </p>