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:
private void BtnSave_Click(object sender, EventArgs e)
{
StockControlBL StBL = new StockControlBL();
StBL.SaveStoreData(StoreParamters As Dictionary(Of String, Object));
}
we will build UI example project as "StoreTransUI.dll"
2- BL Code
Public Function SaveStoreData(ByVal StoreParamters As Dictionary(Of String, Object)) as datatable
private _dt as new datatable()
private _Dl as new DataAccessLayer()
_dt =_dl.ExcuteQuery("SQLStoredProcedureName",SQLParamatersPrm())
return _dt
end function
we will build BL example project as "StoreTransBL.dll"
3- Data Access Layer function:
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
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