SQL数据库连接字符串... [英] SQL Database Connection String...
本文介绍了SQL数据库连接字符串...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中有一个连接字符串,以便:
In my project there is a connection-string such that :
<connectionstrings>
<add name="Employee_Management_System.My.MySettings.EMSDBConnectionString">
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\EMSDB.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</add></connectionstrings>
当我在服务器资源管理器中看到我的数据库的属性时,连接字符串是这样的:
And when I see the properties of my database in server explorer the connection string is such that :
Data Source=(LocalDB)\v11.0;AttachDbFilename="F:\Employee Management System\Employee Management System\EMSDB.mdf";Integrated Security=True
但是我想设置连接字符串,就像我上面的那个app.config文件
(即连接字符串字符串应该是这样的它应该自动确定路径)
当我尝试设置app.config文件中的连接字符串时,我无法访问它。所以如何要做到这一点。
But I want to set connection string like the above which is I app.config file
(i.e, the connection string string should be such that it should automatically determine the path)
And also when I try to set the connection-string which is in app.config file I could not access it.So how to do it.
推荐答案
首先添加引用:System.Configuration
然后在你的代码中:
导入System.Configuration
dim con as SqlConnection
$ B $加载事件或任何事件y你想写:
-------------------------------------- ---------------
con =新的SqlConnection(ConfigurationManager.ConnectionStrings(Constr)。ConnectionString)
--- -------------------------------------------------- -
名称Cnstr是app.config文件中的connectionString的名称
First add reference : System.Configuration
then in your code :
Imports System.Configuration
dim con as SqlConnection
in Load Event or whichever event you want write:
-----------------------------------------------------
con = New SqlConnection(ConfigurationManager.ConnectionStrings("Constr").ConnectionString)
-------------------------------------------------------
the name "Cnstr" is the name of connectionString which is in app.config file
这篇关于SQL数据库连接字符串...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文