访问另一个目录中的DAL(数据访问层) [英] Accessing a DAL (Data Access Layer) in another directory

查看:72
本文介绍了访问另一个目录中的DAL(数据访问层)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任何帮助,将不胜感激.首先是场景:我有一个Intranet项目,其中包含一个数据访问层.dll("DB_DAL.dll"位于完全独立的项目目录中;根据同事发送给我的XML文件),其中包含所有各种存储过程.我想使用另一个vb.net项目访问相同的.dll文件.我在传递连接字符串的语法方面遇到了困难.我尝试了一些在互联网上找到的建议,而我得到的最接近的建议是以下绑定到常规按钮的代码段:

Hi,

Any help on this would be greatly appreciated. First the scenario: I have an intranet project that contains a Data Access Layer .dll (the "DB_DAL.dll" is in a completely separate project directory; the namespace is "DB.DAL" and the class is "SP" according to the XML file a colleague sent to me) containing all the various stored procedures. I would like to access that same .dll file using another vb.net project. I''m having a difficult time as to the syntax for passing a connection string. I''ve tried a number of suggestions I found on the internet and the closest I''ve gotten is the snippet below bound to a regular button:

Public Sub loadDLL()
    Dim strLocation As String
    strLocation = "C:\Intranet\Bin\"
    Dim bytes() As Byte = File.ReadAllBytes(strLocation & "DB_DAL.dll")
    Dim asse As Assembly = Assembly.Load(bytes)
    Dim dtData As DataTable
    dtData = New DataTable
    Dim o As Object = asse.CreateInstance("DB_DAL.SP")
    o.PAAssetTypes_List_Fill(dtData)
    asse = Nothing
    dtData = Nothing
    o = Nothing
End Sub



一切运行良好,直到我碰到 bolded 代码行,并吐出对象变量或未设置块变量".我唯一能想到的是没有发送连接字符串.发送我的连接字符串的语法是什么?一旦清除了这一障碍,在DAL中传递存储过程的参数的语法是什么?这可行吗,或者我只是用这种方法走错了路?再说一次,我在网上找到了这种方法,这不像我以前必须尝试过的那样,所以这对我来说是新的领域.我非常愿意尝试另一种方法,该方法不需要将此DAL放入GAC或我的项目文件夹中.我也无法通过使用Visual Studio中的菜单来引用它,因为DAL在各种服务器环境上的不同位置,这意味着我将位置存储在app.config文件中并对其进行调整.文件.如果您确实有另一种方法,那么代码示例将不胜感激,因为当前问题的语法似乎是最大的障碍.任何帮助将不胜感激.谢谢您的时间!



Things run fine until I hit the bolded line of code and it spits out "Object variable or With block variable not set." The only thing I can think of is that the connection string is not being sent. What would the syntax be for sending my connection string? Once I''ve cleared that hurdle, what would the syntax be for passing parameters for the stored procedures within the DAL? Is this feasible or am I just going down the wrong path with this approach? Again, I found this approach online and it''s not like I have had to try this before so this is new territory for me. I am more than willing to try another approach that does not require putting this DAL into the GAC or my project folder. I also can''t reference it by using the menu in Visual Studio since the DAL is in a different location on the various server environments which means I''ll be storing the location in the app.config file and just make adjustments to that file. If you do have another approach, a code sample would be greatly appreciated since the syntax for my current issue seems to be the biggest hurdle. Any help would be greatly appreciated. Thank you for your time!

推荐答案

Imports System.Reflection

//Take a look 
Dim asse As [Assembly] = [Assembly].LoadFrom(bytes)
Dim Arguments()As Object={"Matrix of arguments sliding to method"}
Dim AType As Type=asse.GetTypes(0)
Dim obj As Object=asse.CreateInstance(AType.FullName)
AType.InvokeMember("SPfunction",BindingFlags.Default Or BindingFlags.InvokeMethod,Nothing,obj,Arguments)


我向您发送此数据库连接的最后提示仅是为了提醒您conn提示,因为我对您的代码有细微的了解.这不是必需的,因为您说您对此很熟悉.
I send you this last tip for db connection only for your conn reminder because I have miniature look into your code.It isn''t necessary because you say that you are familiar with this.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim listOfClasses As New ListBox
       listOfClasses.Location = New Point(210, 300)
        listOfClasses.Width = 300
        listOfClasses.Height = 100
        Controls.Add(listOfClasses)

        Dim dllAdress As New TextBox
        dllAdress.Location = New Point(20, 20)
        dllAdress.Width = 700
        dllAdress.Height = 30
        Controls.Add(dllAdress)


       Dim objAssembly As Assembly
       OpenFileDialog1.ShowDialog()
        dllAdress.Text = OpenFileDialog1.FileName
       objAssembly = System.Reflection.Assembly.LoadFrom(dllAdress.Text)
       For Each [class] In objAssembly.GetTypes
           
           If [class].FullName.IndexOf("NameOfClass") > 0 Then
               listOfClasses.Items.Add([class].FullName)
           End If
       Next
      
   End Sub


有帮助吗?


Is that help ?


这篇关于访问另一个目录中的DAL(数据访问层)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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