英文:
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-->
并获得以下错误消息。
解决方案
您需要在服务器上安装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.
<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.
Solution
You need to install the Microsoft SQL Server in your server and make sure it can be accessed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论