VB.Net decreased speed
-
Hi there, i have a project with many forms and with many dataadapter, SqlCommand´s, and SqlConnection´s generated from the assistend. Now is if i insert more and more the speed between changing the form´s increased and all will work slower and slower. Every Dataadapter, SQLConnection, etc. try to connect. Can stop the automaticaly connecting in the DOTNET GUI. I know the connection programming in code is faster but is their a solution. THX supi
-
Hi there, i have a project with many forms and with many dataadapter, SqlCommand´s, and SqlConnection´s generated from the assistend. Now is if i insert more and more the speed between changing the form´s increased and all will work slower and slower. Every Dataadapter, SQLConnection, etc. try to connect. Can stop the automaticaly connecting in the DOTNET GUI. I know the connection programming in code is faster but is their a solution. THX supi
Sure, you need to redesign everything! First, you should start by creating simple DataAccess components. I like to do this in a standalone DLL which I can use for all my Projects. Within the DLL, I have a public Class call "DataSource". I encapsulate ALL Connection information here and make it super simple to use. For example, "DataSource.Connect", "DataSource.DisConnect" and all error handling is done within the Class. Now, within my "Central" project, I create 1 Public Variable (or Shared Variable in VB.NET) and place it either inside a Globals Module (in VB6) or within the MDIForm (in VB.NET as a Shared Variable). Doing this allows all my Forms to use 1 Connection link into the Database. I will Post next the DataSource Class which I use. It is very simple to use, here's an Example: 'Initialize the Application MainMDI.DataSource = New ActiveDataObjects.DataSource() With MainMDI.DataSource .DatabaseType = ActiveDataObjects.DataSource.DatabaseTypes.dbSQLServer .Server = "(Local)" .Database = "MyDatabase" .UserID = "UserID" .Password = "password" End With The DataSource automatically knows when to initialize a Connection if one doesn't already exist, and it knows how to Connect / DisConnect using the Proper IDBConnection Object optimized for the "DatabaseType" specified. I have Connection strings implemented for almost all DBTypes, but more can be simply Implemented by editing the DatabaseType enum and modifiying the Code (look for ConnectionStrings on www.connectionstrings.com).
-
Hi there, i have a project with many forms and with many dataadapter, SqlCommand´s, and SqlConnection´s generated from the assistend. Now is if i insert more and more the speed between changing the form´s increased and all will work slower and slower. Every Dataadapter, SQLConnection, etc. try to connect. Can stop the automaticaly connecting in the DOTNET GUI. I know the connection programming in code is faster but is their a solution. THX supi
Here's the DataSource Class: Option Strict On Option Explicit On '<><><><><><><><><><><><><><><><><><><><> 'Imports Imports System.Data.OleDb Imports System.Data.SqlClient Imports Microsoft.Data.Odbc '<><><><><><><><><><><><><><><><><><><><> 'Class to encapsulate Data Access '<><><><><><><><><><><><><><><><><><><><> Public NotInheritable Class DataSource '<><><><><><><><><><><><><><><> #Region "Declarations" 'Implementations Implements IDisposable 'Enumerations Public Enum DatabaseTypes dbAccess dbExcel dbODBC dbFileDSN dbSQLRemote dbSQLServer dbSybase5 dbSybase6 dbSybase7 End Enum Public Enum SQLProtocols sqlNamedPipes sqlTCPIP sqlSPXIPX sqlBanyanVines sqlRPC End Enum 'When connecting through the SQLOLEDB provider use the syntax Network Library=dbmssocn and when connecting through MSDASQL provider use the syntax Network=dbmssocn Public Enum SecuirtyProtocols StandardSecurity = 0 TrustedSecurity = 1 End Enum 'Property Variables Private _Server, _RemoteServer, _Database, _DSN, _Address, _ConnectString As String Private _User, _Password As String Private _TimeOut, _Port As Integer Private _UseIntegrated, _UsePrompt As Boolean Private _Type As ActiveDataObjects.DataSource.DatabaseTypes Private _Protocol As ActiveDataObjects.DataSource.SQLProtocols Private _Security As ActiveDataObjects.DataSource.SecuirtyProtocols 'Variables Private odbcCon As Microsoft.Data.Odbc.OdbcConnection Private odbcAdapter As Microsoft.Data.Odbc.OdbcDataAdapter Private oleCon As System.Data.OleDb.OleDbConnection Private oleAdapter As OleDb.OleDbDataAdapter Private sqlCon As System.Data.SqlClient.SqlConnection Private sqlAdapter As SqlClient.SqlDataAdapter Private bConnected, bDisposed As Boolean #End Region '<><><><><><><><><><><><><><><> '<><><><><><><><><><><><><><><> #Region "Properties" 'Property to Return the Connection Object Public ReadOnly Property Connection() As System.Data.IDbConnection Get If (IsNothing(_ConnectString)) OrElse (_ConnectString.Length = 0) Then Exit Property If (Not bConnected) Then Call Me.Connect() 'Determine if Connected Select Case _Type
-
Hi there, i have a project with many forms and with many dataadapter, SqlCommand´s, and SqlConnection´s generated from the assistend. Now is if i insert more and more the speed between changing the form´s increased and all will work slower and slower. Every Dataadapter, SQLConnection, etc. try to connect. Can stop the automaticaly connecting in the DOTNET GUI. I know the connection programming in code is faster but is their a solution. THX supi
To make a Connection using this is simple. Using "Option Strict": Dim sqlCon As SQLClient.SQLConnection = Ctype(DataSource.Connection, SQLClient.SQLConnection) Not using Option Strict: Dim sqlCon As SQLClient.SQLConnection = DataSource.Connection Even if you don't explicitly call "DataSource.Connect", the DataSource class knows it needs to make a Connection.