从Visual Studio 2017 “Server Explorer” 获取数据库 连接信息字符串 ConnectionString

一般情况下,程序员需要手动编写ConnectionString。在这里,我们引入一种从Visual Studion获取连接信息的方法。这样子我们就可以从IDE里得到数据库或者文件的连接信息字符串

由于我的Visual Studion是英文版,有些插图和按钮无法进行翻译,请见谅。为了文档的正确性,我保留了英文的说明和步骤截图。希望可以得到您的体谅。

To get the connection string, we need to add the database in our Server Explorer. Click “View” in the Visual Studio main menu, then click the “Server Explorer”.

Now, right click the “Data Connections”, choose “Add Connections”. Then you can specify the data source type you want. Just like the pop up below.

In my case, it is just my local SQL Server, I choose “Microsoft SQL Server”. After choosing the data source type, you may now get the Server Setting pop up. You need to type in the “Server Name” if the Dropdown could not help to find your database.

After choosing the Server Name, you may specify the Database Name. Then click ok button.

If there is no error message pops up, the connection should be good in you Server Explorer. Check your Server Explorer and find your connection.

Now, right click your connection and click “Properties”, check the Properties Section in the right bottom of your Visual Studio.

In the Connection String part, you could get and use the Connection String.

这种方法的好处就是先通过VS连接Data Source,然后通过VS告诉你ConnectionString。这样子就可以很大程度上增加连接信息的正确性。但你依旧要根据你的需求去设定你得到的string,比如加上密码或者数据文件大小的设定。有兴趣的朋友可以研究下设置细节。

Leave a reply:

Your email address will not be published.

Site Footer