Dear Sir
I'm Trying to save from the DbContext module to the config connectionstring and call the config connectionstring in DbContext module with VB.NET
Please Guide me
Thanks
So I want to save the connectionstring from the below module to the application config
Imports System.Data.OleDb
Public Module DbContext
Public Function GetOledbConnectionString() As String
Return "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\WAREHOUSEGB.accdb;Persist Security Info=False;"
End Function
Public Function GetOledbConnectionStringgoogledrive() As String
Return "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\My Drive\MASTERITEMBORDIRFINAL.accdb;Persist Security Info=False;"
End Function
End Module
Public Function GetConnection() As OleDbConnection
Return New OleDbConnection(GetOledbConnectionString())
End Function
Below is the connection string code in each of the classes I call from the dbcontext module so how can I call it can be called directly from the config application
Public Class SizeProductService
Private ReadOnly _conn As OleDbConnection
Private _connectionString As String = DbContext.GetOledbConnectionStringgoogledrive()
Public Sub New()
_conn = New OleDbConnection(_connectionString)
End Sub
End Class
Public Class StocksinService
Private ReadOnly _conn As OleDbConnection
Private _connectionString As String = DbContext.GetOledbConnectionString()
Public Sub New()
_conn = New OleDbConnection(_connectionString)
End Sub
End Class
Public Class UserDao
Public Function Login(ByVal username As String, ByVal password As String) As User
Using connection = DbContext.GetConnection()
connection.Open()
End Using
End Function
let me know if anything is not clear
Thanks
The app.config becomes like this
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WindowsApplication23.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<applicationSettings>
<WindowsApplication23.My.MySettings>
<setting name="conString" serializeAs="String">
<value>Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\WAREHOUSEGB.accdb;Persist Security Info=False;</value>
</setting>
<setting name="conStringGoogleDrive" serializeAs="String">
<value>Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\My Drive\MASTERITEMBORDIRFINAL.accdb;Persist Security Info=False;</value>
</setting>
</WindowsApplication23.My.MySettings>
</applicationSettings>
</configuration>