Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Cannot establish local connection to SQL SERVER

Cannot establish local connection to SQL SERVER

Scheduled Pinned Locked Moved ASP.NET
asp-netdatabasesysadmincsharpsql-server
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Dunlop
    wrote on last edited by
    #1

    Hi, I'm using ASP.NET Core 6. I'm trying to establish a local connection with SQL SERVER. The authentication method is Windows Auth. I used the following code in appsettings.json:

    "ConnectionStrings": {
    "AuthConnectionString": "Server=.;Database=AspNetAuth;Trusted_Connection=True"
    }

    And following code in program.cs:

    builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("AuthConnectionString")));
    builder.Services.AddIdentity().AddEntityFrameworkStores();

    I created Migration, but when I try to update database, the following error is occured:

    Quote:

    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)

    L Richard DeemingR J A 4 Replies Last reply
    0
    • A Alex Dunlop

      Hi, I'm using ASP.NET Core 6. I'm trying to establish a local connection with SQL SERVER. The authentication method is Windows Auth. I used the following code in appsettings.json:

      "ConnectionStrings": {
      "AuthConnectionString": "Server=.;Database=AspNetAuth;Trusted_Connection=True"
      }

      And following code in program.cs:

      builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("AuthConnectionString")));
      builder.Services.AddIdentity().AddEntityFrameworkStores();

      I created Migration, but when I try to update database, the following error is occured:

      Quote:

      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)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Are you sure that . is a valid server address?

      Richard DeemingR 1 Reply Last reply
      0
      • L Lost User

        Are you sure that . is a valid server address?

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        In a SQL connection string, . resolves to the local computer. You can even use it with a named instance - for example: server=.\SQLEXPRESS


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        L 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          In a SQL connection string, . resolves to the local computer. You can even use it with a named instance - for example: server=.\SQLEXPRESS


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Thanks, not seen it used before.

          1 Reply Last reply
          0
          • A Alex Dunlop

            Hi, I'm using ASP.NET Core 6. I'm trying to establish a local connection with SQL SERVER. The authentication method is Windows Auth. I used the following code in appsettings.json:

            "ConnectionStrings": {
            "AuthConnectionString": "Server=.;Database=AspNetAuth;Trusted_Connection=True"
            }

            And following code in program.cs:

            builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("AuthConnectionString")));
            builder.Services.AddIdentity().AddEntityFrameworkStores();

            I created Migration, but when I try to update database, the following error is occured:

            Quote:

            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)

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            There are many possible causes of that error. For example, do you have a default instance[^] (not a named instance) of SQL Server running on your local computer? Is it properly configured to accept named pipe connections[^]? Is your Windows account correctly configured for access[^]?


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            1 Reply Last reply
            0
            • A Alex Dunlop

              Hi, I'm using ASP.NET Core 6. I'm trying to establish a local connection with SQL SERVER. The authentication method is Windows Auth. I used the following code in appsettings.json:

              "ConnectionStrings": {
              "AuthConnectionString": "Server=.;Database=AspNetAuth;Trusted_Connection=True"
              }

              And following code in program.cs:

              builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("AuthConnectionString")));
              builder.Services.AddIdentity().AddEntityFrameworkStores();

              I created Migration, but when I try to update database, the following error is occured:

              Quote:

              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)

              J Offline
              J Offline
              jsc42
              wrote on last edited by
              #6

              A SO answer at "sql server - What is a Trusted Connection? - Stack Overflow[^]" has 'Trusted_Connection=Yes;', not 'Trusted_Connection=True;'. Worth a try?

              Richard DeemingR 1 Reply Last reply
              0
              • J jsc42

                A SO answer at "sql server - What is a Trusted Connection? - Stack Overflow[^]" has 'Trusted_Connection=Yes;', not 'Trusted_Connection=True;'. Worth a try?

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                Both the System.Data.SqlClient and Microsoft.Data.SqlClient libraries say that you can use true, yes, or SSPI for the value, and either Trusted_Connection or Integrated Security as the key. The "strongly recommended" version is Integrated Security=SSPI. SqlConnection.ConnectionString Property (Microsoft.Data.SqlClient) | Microsoft Docs[^] SqlConnection.ConnectionString Property (System.Data.SqlClient) | Microsoft Docs[^]


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                1 Reply Last reply
                0
                • A Alex Dunlop

                  Hi, I'm using ASP.NET Core 6. I'm trying to establish a local connection with SQL SERVER. The authentication method is Windows Auth. I used the following code in appsettings.json:

                  "ConnectionStrings": {
                  "AuthConnectionString": "Server=.;Database=AspNetAuth;Trusted_Connection=True"
                  }

                  And following code in program.cs:

                  builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("AuthConnectionString")));
                  builder.Services.AddIdentity().AddEntityFrameworkStores();

                  I created Migration, but when I try to update database, the following error is occured:

                  Quote:

                  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)

                  A Offline
                  A Offline
                  Alex Dunlop
                  wrote on last edited by
                  #8

                  I used app.UseAuthentication and the problem solved.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups