如果将 [user instances=true] 添加到连接字符串,则抛出异常 [英] If add [user instances=true] to connection string, an exception is thrown

查看:22
本文介绍了如果将 [user instances=true] 添加到连接字符串,则抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异常详情:

System.Data.SqlClient.SqlException: 无法打开登录请求数据库RealtyDB"登录失败.帐号FAFHN24BNK43\JKAD754"登录失败.

System.Data.SqlClient.SqlException: can not open the logon request database "RealtyDB" login failed. account 'FAFHN24BNK43\JKAD754' login failed.

我的连接字符串如下所示:

My connection string looks like this:

add name = "ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;User Instance=True;Initial Catalog=RealtyDB;Integrated Security=SSPI;"
         providerName="System.Data.SqlClient"       

如果我删除了 [User Instance=True;],我的应用程序会很好.

if I removed the [User Instance=True;], my application will be fine.

有人知道为什么吗?

推荐答案

我只见过与 AttachDbFileName 结合使用的用户实例功能.换句话说,您不能连接到已经连接到正在运行的 SQL Server 实例的数据库,并告诉 SQL Server 为该数据库启动一个新实例,因为只有一个实例可以拥有"一个数据库.时间.当您使用 AttachDbFileName 时,它会告诉 SQL Server 制作该 MDF 文件的副本以供应用程序使用.

I've only ever seen the user instance feature used in combination with AttachDbFileName. In other words, you can't connect to a database that is already attached to a running instance of SQL Server, and tell SQL Server to spin up a new instance for that database, since only one instance can "own" a database at a time. When you use AttachDbFileName, it tells SQL Server to make a copy of that MDF file for the use of the application.

因此,除非您打算以这种方式使用此功能,否则我再次建议您只需从连接字符串中取出 User Instance = true 参数即可.

So, unless this is the way you intend to use this feature, I'll suggest again that you just take the User Instance = true parameter out of your connection string.

(有趣的是,这个可疑的有用功能已被弃用.)

(It may also be interesting to note that this questionably useful feature has been deprecated.)

这篇关于如果将 [user instances=true] 添加到连接字符串,则抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆