无法从已发布的 ASP.NET Core MVC 6.0 项目连接到 MSSQL LocalDB 吗?

huangapple go评论62阅读模式
英文:

Is it impossible to connect MSSQL localdb from published asp net core mvc 6.0 project?

问题

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 a local folder and deployed it using IIS Manager.
However, after publishing, I tried to browse but failed because it failed to connect to the local database.
How can I resolve this problem?

I saw a lecture titled "How to Publish an ASP .NET Core 6 Website _ APP on a Windows OS and Fix Database Connection Problem."
I tried to resolve it using this method.
From "Microsoft Sql Server Management Studio," I created a new login as SQL Server authentication.
Then I changed the connection string in appsettings.json like this:

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

And I published using this connection string. However, I saw an 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 following your guidance.
However, I didn't succeed.

英文:

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.

答案1

得分: 1

我也在使用本地数据库,并遇到了相同的问题。您可以在web.config文件中添加以下代码,然后您将获得更详细的错误消息。

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

我的示例web.config文件。

<?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-->

并获得以下错误消息。

无法从已发布的 ASP.NET Core MVC 6.0 项目连接到 MSSQL LocalDB 吗?

解决方案

您需要在服务器上安装Microsoft SQL Server,并确保可以访问它。

英文:

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.

&lt;environmentVariables&gt;
     &lt;environmentVariable name=&quot;ASPNETCORE_ENVIRONMENT&quot; value=&quot;Development&quot; /&gt;
&lt;/environmentVariables&gt;

My sample web.config file.

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

And get below error message.

无法从已发布的 ASP.NET Core MVC 6.0 项目连接到 MSSQL LocalDB 吗?

Solution

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

huangapple
  • 本文由 发表于 2023年5月30日 05:25:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定