如何将app.config文件连接到vb.net中的DAL层以检索连接. [英] How to connect the app.config file to the DAL layer in vb.net to retrieve the connection.

查看:64
本文介绍了如何将app.config文件连接到vb.net中的DAL层以检索连接.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以为我提供如何将app.config文件连接到vb.net中的DAL层以检索连接"的简短描述.如果可能,我可以得到一个简单的例子吗?

预先致谢

Can someone please provide me with brief description of "How to connect the app.config file to the DAL layer in vb.net to retrieve the connection."If possible can i get a simple example of the same??

Thanks In advance

推荐答案

DAL(数据访问层)不算什么,只是一个用于与数据库交互的单独的类文件.它可以包含(连接,更新,插入,删除,选择等)方法.

对于连接,您可以尝试以下代码:

将连接搅拌存储在app.config中,如下所示:
DAL(Data Access Layer) is nothing, just a separate class file for interacting with database. It can contains methods for (connection,updation, insertion,deletion, selection etc.)

For connection you can try below code:

Store your connection stirng in the app.config like this:
< connectionStrings >
< add name="YourName"

connectionString="Persist Security Info=False;Data Source=Database_Name;Initial Catalog=Table_Name;Integrated Security=SSPI;Trusted_Connection=TRUE;Application Name=Application_Name"

providerName="System.Data.SqlClient" />
< /connectionStrings >



在您的DAL中,您可以这样写:



In you DAL you can write this:

Public Shared Function GetConnectionString(ByVal strConnection As String) As String
   'Declare a string to hold the connection string
   Dim sReturn As New String("")
   'Check to see if they provided a connection string name
   If Not String.IsNullOrEmpty(strConnection) Then
      'Retrieve the connection string fromt he app.config
      sReturn = ConfigurationManager. & _
      ConnectionStrings(strConnection).ConnectionString
   Else
      'Since they didnt provide the name of the connection string
       'just grab the default on from app.config
      sReturn = ConfigurationManager. & _
      ConnectionStrings("YourConnectionString").ConnectionString
   End If
   'Return the connection string to the calling method
   Return sReturn
End Function



希望对您有所帮助:)



hope it helps :)


这篇关于如何将app.config文件连接到vb.net中的DAL层以检索连接.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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