Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have Windows application created by VB.net and c# with 3 layer:
1-Data Access Layer : to connect and execute CRUD Operations using ADO.net
2-Class Library "BL": contains all Operation Functions like CreateStore, CreateTrans ...Etc
3- Windows forms projects UI: call Functions from reference Class Library "BL" to do all functionality, and All "BL" Dll(s) in the same Directory of "Binaries" that Contains Dll(s) of UI also.
My Issue is performance Issue because all of three layers on Client Machine to make any process must connect to Database server and execute the SQL Statement on Database server.
so , i need to move all Data Access layer and Class Library "BL" on the Same Database server or Application Server in the same location to avoid Connectivity Issues and left UI on Client Machine but still read the References of "BL".
thanks

What I have tried:

i tried to make windows Forms Project reference Path in Config file, but don't know how to make reference will read it in run time.

Explain:
1- UI Code vb.net or c# project (windows forms project(s) Or Class library project(s)) ,
so i have many User Interfaces execute the same BL function:
C#
private void BtnSave_Click(object sender, EventArgs e)
        {
         StockControlBL StBL = new StockControlBL(); //create instance from BL 
         StBL.SaveStoreData(StoreParamters As Dictionary(Of String, Object)); // Call Function to create New Store
        }

we will build UI example project as "StoreTransUI.dll"
2- BL Code
VB.NET
'vb. project to make all BL Functions. for example create new store
 Public Function SaveStoreData(ByVal StoreParamters As Dictionary(Of String, Object)) as datatable
    private _dt as new datatable()
    private _Dl as new DataAccessLayer()
' some code of Validations 
    _dt =_dl.ExcuteQuery("SQLStoredProcedureName",SQLParamatersPrm()) 
    return _dt

end function

we will build BL example project as "StoreTransBL.dll"

3- Data Access Layer function:

VB.NET
 Private ConnectionString As String
<pre> Private Sub InitClass()

        Dim xmlDoc As New XmlDocument

        xmlDoc = New XmlDocument()
        Dim x As String = AppDomain.CurrentDomain.BaseDirectory
        Try
            Dim objReader As New System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory & "app.config")
            Dim allString As String
            allString = objReader.ReadToEnd
           
          
            Dim sr As New System.IO.StringReader(allString )
            xmlDoc.Load(sr)


        Catch ex As Exception
            Throw (New Exception(ex.Message, ex.InnerException))
        End Try
     
        Dim xn As XmlNode

        xn = xmlDoc.SelectSingleNode("connectionstring")

        ConnectionString = xn.InnerText

    
    End Sub

VB.NET
Public Function ExecProc(ByVal StoredProcedure As String, ByVal Paramters As Dictionary(Of String, Object)) As DataTable
        Dim DtProc As DataTable
        Dim Dset As New DataSet
        Dim Trans As SqlTransaction = Nothing
        If ConnectionType = 0 Then
            Dim cnSQL As SqlConnection = New SqlConnection(ConnectionString)

            Dim cmdSel As SqlCommand = New SqlCommand(StoredProcedure, cnSQL)
            If cnSQL.State = ConnectionState.Closed Then
                cnSQL.Open()
            End If

            If cnSQL.State = ConnectionState.Open Then

                cmdSel.CommandType = CommandType.StoredProcedure
                Dim SqlAdapt As New SqlDataAdapter(cmdSel)
                If Not IsNothing(Paramters) Then
                    For Each param As KeyValuePair(Of String, Object) In Paramters
                        cmdSel.Parameters.Add(New SqlParameter(param.Key, param.Value))
                    Next
                End If
                Try
                    SqlAdapt.Fill(Dset)
                    Trans = cnSQL.BeginTransaction


                    Trans.Commit()
                Catch ex As Exception
                    Trans.Rollback()
                    cnSQL.Close()
                    cnSQL.Dispose()
                Finally
                    If cnSQL.State = ConnectionState.Open Then
                        cnSQL.Close()
                        cnSQL.Dispose()
                    End If
                End Try
            End If

        End If
        If Dset.Tables.Count > 0 Then
            DtProc = Dset.Tables(0)
            Dset.Tables.Clear()
            Return DtProc
        Else
            Return New DataTable
        End If

    End Function 

we will build DataAccessLayer example project as "DataAccessLayer.dll"
all layers files for example:(StoreTransUI.dll,StoreTransBL.dll,DataAccessLayer.Dll and App.config) in the same folder in client machine ,
actually the folder contains more than 700 files of UI and BL and DataAccessLayer.dll file and App.config file,
My issue is : i want to move All BL and Dataaccesslayer and App.config(to get SQL Database connection string ) in Database Server
and left Only UI on Client(s) machine to enhance connection Issues.
thanks
Posted
Updated 19-Jan-21 4:12am
v2
Comments
RickZeeland 18-Jan-21 7:13am    
So you want each client to have it's own database (SQL Server I assume) ?
[no name] 18-Jan-21 8:03am    
If you want to "offload" from the client, you need specify what database server you are using and then examine your SQL in terms of it's proper work load. Then you can start thinking in terms of what else in terms of a library / app server. 3 layers means nothing if it wasn't partitioned properly in the first place.
mohamad Ezz 18-Jan-21 9:35am    
no, it's one database and all client machines has copy of binaries folder that contains all binaries files (All three layers) and App.config file and the last one has connection string to to make data access layer connect to database and execute SQL statements. i need to move 2 layers (Data access and BL) to SQL server.
[no name] 19-Jan-21 11:26am    
I told you to examine your SQL ... and you didn't. Trying to control a "transaction" from the client confirms it.
mohamad Ezz 20-Jan-21 1:50am    
what you mean by "Examine your SQL" , i need to remove BL and DL and app.config(Connection string configuration) from all client's machines and left only UI ,and everything still working.
any way thanks for your reply...

You probably want to use settings as explained here: dotnetperls settings[^]

And here is an example with an SQL Server connection: How to get Connection String from App.Config in C#[^]
 
Share this answer
 
v2
You don't want to do that. Though you may seem like you're solving a problem with doing it this way, you're actually creating more problems.

Once loaded by a process on the client machines, the .DLL's become locked, meaning you cannot replace them unless EVERYONE using the app quits the app. That will unlock the .DLL's so you can replace them.

Also, there are issues with running .NET code from a remote (network share) location. Code not loaded from a local drive is not trusted. It runs in a restricted sandbox that may not give enough permissions for you to do what you want, like database access.

See this: .net - Trusting an assembly located on a network share[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900