Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Srihari Vallabhaneni 2 posts 83 karma points
    Aug 04, 2023 @ 17:58
    Srihari Vallabhaneni
    0

    Umbraco 10.5.1 connecting to local database when working locally

    Hi I am struggling to connect my Umbraco 10.5.1 (in specific) to a local database in my SQLServer.

    I got an upgraded database which has all the content but when I tried to connect locally I was getting an error "A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."

    After few tries and changing the settings as per the error, I found that its looking for a DB file located in UmbracoProject\umbraco\Data\Umbraco.mdf.

    So got the database file from SQL default location and copied it to the above file location. Now I was getting the error "The database failed to install. ERROR: Database configuration is invalid. Please check that the entered database exists and that the provided username and password has write access to the database."

    It took me pretty much 3-4 days and gone through all the knowledge base but dont find any help anywhere from Umbraco on how to connect to local database for an Umbraco 10 and above install.

    All I can see was about how we can connect our local project to Umbraco Cloud which is not what I need.

    Error message when trying to connect to local database

    This was my local setup in the appsettings.json

    {
      "$schema": "./appsettings-schema.json",
      "Serilog": {
        "MinimumLevel": {
          "Default": "Information",
          "Override": {
            "Microsoft": "Warning",
            "Microsoft.Hosting.Lifetime": "Information",
            "System": "Warning"
          }
        }
      },
      "ConnectionStrings": {
        "umbracoDbDSN": "Server=(localdb)\\MSSQLLocalDB;Database=Umbraco;Trusted_Connection=True;MultipleActiveResultSets=true;Integrated Security=true",
        "umbracoDbDSN_ProviderName": "Microsoft.Data.SqlClient"
      },
      "Umbraco": {
        "CMS": {
          "Global": {
            "Id": "3d2b5fa7-bbf0-4092-a3a9-41dfbcd5u30a",
            "SanitizeTinyMce": true
          },
          "Deploy": {
            "Settings": {
              "PreferLocalDbConnectionString": true
            }
          },
          "Content": {
            "ContentVersionCleanupPolicy": {
              "EnableCleanup": true
            }
          }
        }
      }
    }
    

    I found this article earlier which is similar but instead I want to connect to local (external) database instead of Umbraco cloud database.

    https://our.umbraco.com/forum/using-umbraco-and-getting-started/109924-umbraco-10-and-external-database-access-by-nuget-package-microsoftdatasqlclient

    Can anyone please help if anyone come across this or Is Umbraco Cloud is the only option to connect to when we upgrade to any version above 9.

  • Wouter van de Weerd 6 posts 118 karma points notactivated
    Aug 12, 2023 @ 13:02
    Wouter van de Weerd
    101

    For the database connection with my hosting provider, using SQLServer 2016/2019, I use the connection string;

    "ConnectionStrings": {
            "umbracoDbDSN": "server=[SERVER-NAME OR IP-ADDRESS];database=[DATABASENAME];user id=[USERID];password=[PASSWORD]",
            "umbracoDbDSN_ProviderName": "Microsoft.Data.SqlClient"
        },
    

    Just remove the "[]" and configure the values between them according to your database settings.

    PS: "(localdb)\MSSQLLocalDB" in your connection string refers to the MDF file.

  • Srihari Vallabhaneni 2 posts 83 karma points
    Aug 15, 2023 @ 08:26
    Srihari Vallabhaneni
    1

    Thanks Wouter van de Weerd. That worked.

Please Sign in or register to post replies

Write your reply to:

Draft