如何从一个数据库的连接字符串 [英] How to get the connection String from a database

查看:81
本文介绍了如何从一个数据库的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建了SQL Server Management Studio中的数据库,我想现在我的C#应用​​程序中使用它。我需要的连接字符串?

I have created a database with SQL Server Management Studio, I would like to now use it in my C# application. I need the connection string?

我在哪里可以找到连接字符串,并将其存储我的数据库在哪里?

Where can I find the connection string, and where is my database stored?

我必须将它发布之类的东西,或者是在我的文档的地方?

Do I have to publish it or something like that, or is it in my documents somewhere?

using (var conn = new SqlConnection("your connection string to the database"))

我如何获得的连接字符串?我在哪里可以找到连接字符串粘贴复制到上面的部分?

How do I obtain the connection string? Where can I find the connection string to copy paste into the above section?

如何发布我的数据库,以便Visual Studio可以把它捡起来?然后,我可以只拉那里的连接字符串?

How to I publish my database so that Visual Studio can pick it up? Then I can just pull the connection string of there?

推荐答案

要获得在Visual Studio(使用服务器资源管理器窗口菜单中的查看的连接字符串的最简单的方法,的服务器资源管理器的),并连接到从该窗口中的服务器。

The easiest way to get the connection string is using the "Server Explorer" window in Visual Studio (menu View, Server Explorer) and connect to the server from that window.

这时你可以看到在连接的服务器的属性连接字符串(选择连接和preSS F4或Alt + Enter键或右键菜单上选择属性)。

Then you can see the connection string in the properties of the connected server (choose the connection and press F4 or Alt+Enter or choose Properties on the right click menu).

高级连接字符串设置:创建连接时,您可以通过点击高级修改任何先进的连接字符串的选项,如火星,弹性,timeot,集中配置等。 ..添加连接对话框中关于底部按钮。您可以通过右键单击数据连接,并选择以后访问该对话框中的修改连接...。可用的高级选项因服务器类型而有所不同。

Advanced connection string settings: when creating the connection, you can modify any of the advanced connection string options, like MARS, resiliency, timeot, pooling configuration, etc. by clicking on the "Advanced..." button on the bottom of the "Add connection" dialog. You can access this dialog later by right clicking the Data Connection, and choosing "Modify connection...". The available advanced options vary by server type.

如果您创建使用SQL Server Management Studio中的数据库,该数据库将在服务器实例创建的,所以,部署应用程序,你必须对数据库进行备份,并部署SQL Server的部署中它。或者,你可以(在SQL Server 2012中的LocalDB),将与您的应用程序很容易地分配使用SQL Server防爆preSS使用的数据文件。

If you create the database using SQL Server Management Studio, the database will be created in a server instance, so that, to deploy your application you'll have to make a backup of the database and deploy it in the deployment SQL Server. Alternatively, you can use a data file using SQL Server Express (localDB in SQL Server 2012), that will be easily distributed with your app.

即。如果它是一个ASP.NET应用程序,有一个App_Datafolder。如果你右击它,你可以添加新的元素,它可以是一个SQL Server数据库。此文件将在该文件夹上,将与SQL防爆preSS工作,将是易于部署。你需要在你的机器上安装了SQL防爆preSS /的LocalDB为此工作。

I.e. if it's an ASP.NET app, there's an App_Datafolder. If you right click it you can add a new element, which can be a SQL Server Database. This file will be on that folder, will work with SQL Express, and will be easy to deploy. You need SQL Express / localDB installed on your machine for this to work.

这篇关于如何从一个数据库的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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