该类型的字符串由站点 SOMEE 发出以连接到 SQL Server:
workstation id=xxx.mssql.somee.com;packet size=4096;user id=xxxx;pwd=xxxx;data source=xxxx.mssql.somee.com;persist security info=False;initial catalog=xxxx;
在本地数据库上,我使用以下连接字符串:
我发布了项目并将其上传到somee.com,但无法建立与远程数据库的连接。如何将
SOMEE-DB-CONNECTION-STRING
转换为普通的 Entity Framework Core 7 连接字符串(如本地连接字符串)?
尝试了一些方法,没有找到解决办法。
要使用 Entity Framework Core 将 ASP.NET Web API 连接到 Somee.com 上的 SQL Server 数据库,您可以按如下方式修改连接字符串:
appsettings.json
或 appsettings.Development.json
文件中的连接字符串替换为您由 Somee.com 提供的连接字符串:"ConnectionStrings": {
"DefaultConnection": "workstation id=xxx.mssql.somee.com;packet size=4096;user id=xxxx;pwd=xxxx;data source=xxxx.mssql.somee.com;persist security info=False;initial catalog=xxxx;"
}
Startup.cs
文件中的 ConfigureServices
方法中,将 DbContext 配置为使用此连接字符串:services.AddDbContext<YourDbContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
});
确保将
YourDbContext
替换为 DbContext 的实际名称。
appsettings.json
中指定的连接字符串连接到 Somee.com 提供的远程 SQL Server 数据库。请记住将连接字符串中的占位符 (xxx, xxxx) 替换为您的实际数据库凭据。另外,请确保 Somee.com 上的远程 SQL Server 实例允许外部连接,并且防火墙规则已正确配置以允许您的 Web 应用程序连接到它。