The error message indicates it cannot find the location of SQLUserInstance.dll. Please follow this article to locate and fix the corresponding registry value(s) and try again.
( SQL Server Express LocalDB 2019) provider: SQL Network Interfaces, error: 56
hi, code is
string constr = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True";
SqlConnection connection = new SqlConnection(constr);
try
{
connection.Open();
MessageBox.Show("OK, Can Open!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
but it is not connected.
exception msg is "provider: SQL Network Interfaces, error: 56 ",
more exception info is "在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 56 - 无法从注册表中指定的位置加载 SQLUserInstance.dll。请验证 SQL Server Express 的 Local Database Runtime 功能是否正确安装。"
if this windows has VS2019, these code is ok; but this windows is brand new , these code is not run .
Developer technologies .NET Other
SQL Server Other
Developer technologies C#
-
cheong00 3,486 Reputation points Volunteer Moderator
2021-04-07T04:28:47.447+00:00
4 additional answers
Sort by: Most helpful
-
Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
2021-04-08T21:12:00.51+00:00 but, if i modify Windows Registry, insert
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wow6432Node\Microsoft SQL Server Local DB\Installed Versions\15]
"InstanceAPIPath"="C:\Program Files (x86)\Microsoft SQL Server\15\LocalDB\Binn\SqlUserInstance.dll"The key value should be
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server Local DB\Installed Versions\15.0
. You are missing .0 at the end.And the value should be
C:\Program Files (x86)\Microsoft SQL Server\150\LocalDB\Binn\SqlUserInstance.dll
. You have 15 where it should be 150. And you should have single backslashes.And of course... The file must exist in that location.
-
Timon Yang-MSFT 9,606 Reputation points
2021-04-07T01:46:10.55+00:00 According to your description, I think the biggest possibility is that Sql Server is not installed on the computer where the problem occurs.
When Visual Studio is installed, if you select certain workloads, such as
ASP.NET and web development workload
, Visual Studio will download Sql Server to your machine at the same time. The default name is LocalDB, so this code works on the computer with Visual Studio installed but not on the new computer.You can confirm this information by checking whether the file system has this folder:
C:\Users\<your username>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. -
Shan He 21 Reputation points
2021-04-07T02:46:06.26+00:00 thank u!
the file system has this folder: "C:\Users<my username>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances"
and has some error file in folder "MSSQLLocalDB" .
error file context :
2021-04-07 07:55:22.09 Server Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Express Edition (64-bit) on Windows 10 Pro 10.0 <X64> (Build 19042: )
2021-04-07 07:55:22.09 Server UTC adjustment: 8:00 2021-04-07 07:55:22.09 Server (c) Microsoft Corporation. 2021-04-07 07:55:22.09 Server All rights reserved. 2021-04-07 07:55:22.09 Server Server process ID is 4984. 2021-04-07 07:55:22.09 Server System Manufacturer: 'Dell Inc.', System Model: 'Vostro 3900'. 2021-04-07 07:55:22.09 Server Authentication mode is MIXED. 2021-04-07 07:55:22.09 Server Logging SQL Server messages in file 'C:\Users\admin\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\error.log'. 2021-04-07 07:55:22.09 Server The service account is 'DESKTOP-E6UGLF4\admin'. This is an informational message; no user action is required. 2021-04-07 07:55:22.09 Server Command Line Startup Parameters: -c -S "MSSQL15E.LOCALDB" -s "LOCALDB#C2A22A50" -d "C:\Users\admin\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\master.mdf" -l "C:\Users\admin\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\mastlog.ldf" -e "C:\Users\admin\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\error.log" 2021-04-07 07:55:22.09 Server SQL Server detected 1 sockets with 4 cores per socket and 4 logical processors per socket, 4 total logical processors; using 4 logical processors based on SQL Server licensing. This is an informational message; no user action is required. 2021-04-07 07:55:22.09 Server SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required. 2021-04-07 07:55:22.09 Server Detected 12254 MB of RAM. This is an informational message; no user action is required. 2021-04-07 07:55:22.09 Server Using conventional memory in the memory manager. 2021-04-07 07:55:22.09 Server Page exclusion bitmap is enabled. 2021-04-07 07:55:22.14 Server Buffer Pool: Allocating 2097152 bytes for 1804556 hashPages. 2021-04-07 07:55:22.16 Server Default collation: SQL_Latin1_General_CP1_CI_AS (us_english 1033) 2021-04-07 07:55:22.19 Server Buffer pool extension is already disabled. No action is necessary. 2021-04-07 07:55:22.24 Server Query Store settings initialized with enabled = 1, 2021-04-07 07:55:22.24 Server The maximum number of dedicated administrator connections for this instance is '1' 2021-04-07 07:55:22.24 Server Node configuration: node 0: CPU mask: 0x000000000000000f:0 Active CPU mask: 0x000000000000000f:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required. 2021-04-07 07:55:22.25 Server Using dynamic lock allocation. Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node. This is an informational message only. No user action is required. 2021-04-07 07:55:22.25 Server In-Memory OLTP initialized on lowend machine. 2021-04-07 07:55:22.26 Server [INFO] Created Extended Events session 'hkenginexesession'
2021-04-07 07:55:22.27 Server Database Instant File Initialization: disabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required. 2021-04-07 07:55:22.27 Server Total Log Writer threads: 2. This is an informational message; no user action is required. 2021-04-07 07:55:22.28 Server clflush is selected for pmem flush operation. 2021-04-07 07:55:22.28 Server Software Usage Metrics is disabled. 2021-04-07 07:55:22.31 spid9s Starting up database 'master'. 2021-04-07 07:55:22.35 Server CLR version v4.0.30319 loaded. 2021-04-07 07:55:22.36 spid9s 4 transactions rolled forward in database 'master' (1:0). This is an informational message only. No user action is required. 2021-04-07 07:55:22.37 spid9s 0 transactions rolled back in database 'master' (1:0). This is an informational message only. No user action is required. 2021-04-07 07:55:22.37 spid9s Recovery is writing a checkpoint in database 'master' (1). This is an informational message only. No user action is required. 2021-04-07 07:55:22.38 Server Common language runtime (CLR) functionality initialized using CLR version v4.0.30319 from C:\Windows\Microsoft.NET\Framework64\v4.0.30319. 2021-04-07 07:55:22.44 spid9s SQL Server Audit is starting the audits. This is an informational message. No user action is required. 2021-04-07 07:55:22.45 spid9s SQL Server Audit has started the audits. This is an informational message. No user action is required. 2021-04-07 07:55:22.50 spid9s SQL Trace ID 1 was started by login "sa". 2021-04-07 07:55:22.52 spid9s Server name is 'DESKTOP-E6UGLF4\LOCALDB#C2A22A50'. This is an informational message only. No user action is required. 2021-04-07 07:55:22.52 spid19s Server local connection provider is ready to accept connection on [ \.\pipe\LOCALDB#C2A22A50\tsql\query ]. 2021-04-07 07:55:22.52 spid19s Dedicated administrator connection support was not started because it is disabled on this edition of SQL Server. If you want to use a dedicated administrator connection, restart SQL Server using the trace flag 7806. This is an informational message only. No user action is required. 2021-04-07 07:55:22.52 spid19s SQL Server is now ready for client connections. This is an informational message; no user action is required. 2021-04-07 07:55:22.54 spid14s Starting up database 'mssqlsystemresource'. 2021-04-07 07:55:22.54 spid14s The resource database build version is 15.00.2000. This is an informational message only. No user action is required. 2021-04-07 07:55:22.55 spid9s Starting up database 'msdb'. 2021-04-07 07:55:22.59 spid14s Starting up database 'model'. 2021-04-07 07:55:22.63 spid14s Clearing tempdb database. 2021-04-07 07:55:22.78 spid14s Starting up database 'tempdb'. 2021-04-07 07:55:22.88 spid22s The Service Broker endpoint is in disabled or stopped state. 2021-04-07 07:55:22.88 spid22s The Database Mirroring endpoint is in disabled or stopped state. 2021-04-07 07:55:22.89 spid22s Service Broker manager has started. 2021-04-07 07:55:22.89 spid9s Recovery is complete. This is an informational message only. No user action is required. 2021-04-07 08:14:12.89 Server The RANU instance is terminating in response to its internal time out. This is an informational message only. No user action is required. 2021-04-07 08:14:12.89 spid18s SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required.
-