如何在visual studio 2012中将“用户实例”设置为本地数据库的“true” [英] How do I set 'user instance' to 'true' of local database in visual studio 2012

查看:130
本文介绍了如何在visual studio 2012中将“用户实例”设置为本地数据库的“true”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to set the 'user instance' to 'true' of local database in Visual Studio 2012 as it is needed in making the project as .exe, however, when I try to modify the connection, it gives me an error like: 

'The user instance login flag is not allowed when connecting to a user instance of SQL Server. The connection will be closed.'





我尝试过:





What I have tried:

Here is the connection string:

    `SqlConnection sql = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Karen Kate\Documents\DateRangeTest.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;Context Connection=False");`

推荐答案

你不能在生产中这样做:只有Sql Express支持附加和本地实例作为开发工具:完整版本不支持。

要在完整版本的SQL上使用您的数据库(即在生产中),您需要让安装程序在SQL下创建数据库而不是尝试附加它,然后您的应用程序连接到该数据库。



为什么?好吧,想一想。您的LocalDB实例与dev的代码在同一台机器上,因此SQL可以访问您的HDD。在生产中并非如此:SQL Server安装在专用计算机上,您的应用程序连接到该计算机。该专用计算机无法访问您的文件系统,也无法物理访问您尝试使用的数据库文件。
You can't do that in production: Only Sql Express supports attaching and local instancing as a development tool: the full version does not.
To use your DB on the full version of SQL (i.e. in production) you need to have your installation program create the DB under SQL instead of trying to attach it, then your app connects to that DB.

Why? Well, think about it. Your LocalDB instance is on the same machine as your code for dev, so SQL has access to your HDD. In production that is not what happens: SQL Server is installed on a dedicated machine and your app connects to that. That dedicated machine doesn't have any access to your file system and can't physically access the database file you are trying to use.


这篇关于如何在visual studio 2012中将“用户实例”设置为本地数据库的“true”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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