连接字符串参数不能为空
Connection string parameter cannot be null
我有一个在我的机器上运行的 MVC 核心应用程序,其中 SQLEXPRESS 不是命名实例。当我将它部署到远程计算机上的 IIS 7.5 时,它是一个命名实例,而不更改连接字符串:
"Server=localhost;Database=QuickShare;Trusted_Connection=True;MultipleActiveResultSets=true"
我收到以下错误:
SqlException: A network-related or instance-specific error occurred
while establishing a connection to SQL Server. The server was not
found or was not accessible. Verify that the instance name is correct
and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)
然后我更正 nameD 实例的连接字符串:
"Server=localhost.\SQLEXPRESS;Database=QuickShare;Trusted_Connection=True;MultipleActiveResultSets=true"
我收到以下错误:
ArgumentNullException: Value cannot be null. Parameter name:
connectionString
在开发人员错误页面的堆栈跟踪中,突出显示的是来自 Startup.cs
的以下行:
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
仅更改连接字符串如何从预期的连接异常变为空参数异常?
请记住,您的配置文件是 JSON,这意味着某些字符需要转义,在本例中是反斜杠。所以从 this answer 你可以看到你需要加倍反斜杠。例如:
"Server=localhost\SQLEXPRESS;Database=QuickShare;......"
我有一个在我的机器上运行的 MVC 核心应用程序,其中 SQLEXPRESS 不是命名实例。当我将它部署到远程计算机上的 IIS 7.5 时,它是一个命名实例,而不更改连接字符串:
"Server=localhost;Database=QuickShare;Trusted_Connection=True;MultipleActiveResultSets=true"
我收到以下错误:
SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
然后我更正 nameD 实例的连接字符串:
"Server=localhost.\SQLEXPRESS;Database=QuickShare;Trusted_Connection=True;MultipleActiveResultSets=true"
我收到以下错误:
ArgumentNullException: Value cannot be null. Parameter name: connectionString
在开发人员错误页面的堆栈跟踪中,突出显示的是来自 Startup.cs
的以下行:
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
仅更改连接字符串如何从预期的连接异常变为空参数异常?
请记住,您的配置文件是 JSON,这意味着某些字符需要转义,在本例中是反斜杠。所以从 this answer 你可以看到你需要加倍反斜杠。例如:
"Server=localhost\SQLEXPRESS;Database=QuickShare;......"