0

I made my simple project that save my ideas to "(localdb)\mssqllocaldb".

namespace publish.Models
{
    public class idea
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

I use asp.net.core 6.0 - mvc. I published this project to local folder and deploy using iis manager. However after publishing, I tried browse but failed. Because it is failed to connect local database. How can I resolve this problem?

I saw lecture the name is "How to Publish an ASP .NET Core 6 Website _ APP on a Windows OS and Fix Database Connection Problem". I tried to resolve using this method. From "Microsoft Sql Server management studio", I create new login as sql server authentication. Then change the connection string in appsetting.json like that

"ConnectionStrings": {
    "publishContext": "Server=(localdb)\\mssqllocaldb;Database=publish.Data;uid=ali12;pwd=123;"
  }

And published using this connectionstrings. However, I saw error message like this

Error.
An error occurred while processing your request. Request ID: 00-e7f938a225da4cf8d5148cfd354c0f34-01a9fa13f2a60d36-00 ...

=============================================== Dear Jason Pan, I tried to resolve my problem from your guidance. However, I didn`t success.

Ali Ali
  • 56
  • 6
  • Did you follow the advice with development mode? Please post that error message *with more detailed information about the error that occurred* – Sir Rufo May 30 '23 at 06:14

1 Answers1

1

I also using localdb and facing the same issue. You can add below code in web.config file, then you will get more detailed error message.

<environmentVariables>
     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>

My sample web.config file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\AspCore7_Web_Identity.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
          <environmentVariables>
     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
 </aspNetCore>
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: E938A144-170E-4E89-****-9B88****7039-->

And get below error message.

enter image description here

Solution

You need to install the Microsoft SQL Server in your server and make sure it can be accessed.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Dear Jason Pan. Thanks for your help. I changed web.config file. However same problem occurred. And I installed "Microsoft SQL server management studio" already. However how can I make sure it? I am waiting for your answer detailed. – Ali Ali Jun 01 '23 at 13:57
  • Hi @AliAli, please [follow the steps in my answer](https://stackoverflow.com/a/75480715/7687666), you could [add new database or attach the existing .mdf & .ldf files,](https://www.mssqltips.com/sqlservertip/6222/sql-server-attach-and-detach-database-examples/), and enable it can accept remote connections, then get connectionstrings from vs2022. Finally you will fix the issue. – Jason Pan Jun 02 '23 at 01:33
  • Dear Jason Pan! I succeed to connection "localdb". However, I must install sql express server. Is it impossible to connect localdb using mssql server? – Ali Ali Jun 17 '23 at 08:39