SQL Server Error

Discussion in 'Databases' started by Austin Wilson, Mar 23, 2016.

Tags:
  1. I am new to the site and I have ran into a problem that I can't seem to solve. I am trying to connect to my SQL Server, but get the following error when I try accessing my data:

    <ExceptionMessage>
    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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
    </ExceptionMessage>

    My Web.config connectionStrings is:

    <connectionStrings>
    <add name="SQL2014_985067_cl" connectionString="Data Source=tcp:sql2k1401.discountasp.net;Initial Catalog=SQL2014_985067_cl;User ID=SQL2014_985067_cl_user;Password=PASSWORD;" providerName="System.Data.SqlClient" />
    </connectionStrings>

    Has anyone had an error similar to this? Any help would be greatly appreciated. Thanks.
     
  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    The connection string looks fine. Do you have another active connection string in your web.config file or code? Because it looks like you're trying to connect to an instance of SQL Server Express with LocalDB add-on.
     
    mjp likes this.
  3. Ray,
    Thanks so much for your fast reply! I didn't have any other active connection string I don't believe, but after your response I noticed I was using LocalDB specifications within the <entityFramework> tags so I changed those to Microsoft SQL Server. After seeing "error: 52" all day, I was reluctantly happy to now get "error: 40". Any ideas what could be causing that error?

    <ExceptionMessage>
    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)
    </ExceptionMessage>


    <connectionStrings>
    <remove name="SQL2014_985067_cl"/>
    <add name="SQL2014_985067_cl" connectionString="Data Source=SQL2k1401.discountasp.net;Initial Catalog=SQL2014_985067_cl;Integrated Security=False;User ID=SQL2014_985067_cl_user; Password=*MyPassword*" providerName="System.Data.SqlClient" />
    </connectionStrings>



    <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
    <parameters>
    <parameter value="Data Source=.;Integrated Security=True" />
    </parameters>
    </defaultConnectionFactory>
    <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    </entityFramework>
     
  4. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    I don't see any values here?
     
    mjp likes this.
  5. Thanks again! I am having another problem now however. I tried to research the issue, which led to me adding "Trusted_Connection=False;Persist Security Info = True;
    " to the connection string. However, I still get the same exception message.

    <ExceptionMessage>
    This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.
    </ExceptionMessage>


    <connectionStrings>
    <remove name="SQL2014_985067_cl"/>
    <add name="SQL2014_985067_cl" connectionString="Data Source=tcp:sql2k1401.discountasp.net;Initial Catalog=SQL2014_985067_cl;Trusted_Connection=False;Persist Security Info = True; User ID=SQL2014_985067_cl_user;Password=<MyPassword>;" providerName="System.Data.SqlClient" />
    </connectionStrings>


    <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
    <parameters>
    <parameter value="Data Source=tcp:sql2k1401.discountasp.net;" />
    </parameters>
    </defaultConnectionFactory>
    <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    </entityFramework>
     
  6. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Not really sure, but you can try using the full connection string here.
     
  7. Thanks for all of your help! I switched the value to the full connection string, but started getting the error "CREATE DATABASE permission denied in database 'master'." The change I finally had to make was in my IdentityModels.cs file in the ApplicationDbContext(). Previously it had:

    public ApplicationDbContext()
    : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    I had to change it to:

    public ApplicationDbContext()
    : base("Data Source=tcp:sql2k1401.discountasp.net;Initial Catalog=SQL2014_985067_cl;Trusted_Connection=False;Persist Security Info = True; User ID=SQL2014_985067_cl_user;Password=<MyPassword>;", throwIfV1Schema: false)
    {
    }

    Everything seems to be working fine now thankfully!
     
    mjp and RayH like this.

Share This Page