无法连接到Localdb,但可以使用namedpipe

编程入门 行业动态 更新时间:2024-10-08 02:25:43
本文介绍了无法连接到Localdb,但可以使用namedpipe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我真的很讨厌将我的应用程序连接到数据库.我试图在连接字符串中使用(localdb)\ MSSQLLocalDB 连接到数据库,但出现此错误:

I am really suck with connecting my app to a database. I am trying to connect to a database using (localdb)\MSSQLLocalDB in the connection string and I get this error:

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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details. )

我可以使用(localdb)\ MSSQLLocalDB

因此,为了进行测试,我将数据源更改为实例的命名管道,并且可以从(我的应用程序)Web配置和SSMS连接到数据库.唯一的问题是实例在不活动后停止,并且当我手动重启实例时,命名管道已更改.

So to test things I changed my datasource to the named pipe of my instance, and I can connect to the db from (my app) web config and SSMS. Only issue with that is that the instance stops after inactivity and when I restart the instance (manually), the named pipe is changed.

任何人都可以帮助我解决无法使用localdb进行连接的问题吗?

Can anyone please help me resolve the issue of not being able to connect using localdb?

我正在使用的连接字符串:

Connection strings I am using:

工作:

<add name="constr" connectionString="Data Source=np:\\.\pipe\LOCALDB#FF072C16\tsql\query;Initial Catalog=hands; Integrated Security=True" providerName="System.Data.SqlClient" />

不起作用:

<add name="constr" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=hands; Integrated Security=True" providerName="System.Data.SqlClient" />

推荐答案

进一步调查后,我在应用程序甚至查看器"中发现了这些错误

After further investigation I found these errors in the Application even viewer

Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user. Windows API call SHGetKnownFolderPath returned error code: 5. Windows system error message is: Access is denied. Reported at line: 422.

这促使我找到解决该问题的这篇文章.

Which led me to find this article that solved the issue.

主要是我必须进行以下更改:

Mainly I had to do these changes:

1. Change the loadUserProfile="true" to true for the App Pool running the app. 2. Create a share for my localdb instance and use that in my connection string. 3. Change the local instance stop time to indefinite Run the following batch to change the timeout to 65535. This value is in seconds, but 65535 is the magic number meaning infinite: exec sp_configure 'user instance timeout',65535 reconfigure exec sp_configure 'user instance timeout' go

blogs.msdn.microsoft/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-1-user-profile/

blogs.msdn.microsoft/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-2-instance-ownership/

更多推荐

无法连接到Localdb,但可以使用namedpipe

本文发布于:2023-10-16 14:04:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   连接到   Localdb   namedpipe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!