M
Matiwure
Guest
l am an inexperienced programmer working on a small vb.net project. l am using three tier approach and l have installed Microsoft enterprise library 6 to help me work with SQL server stored procedures but when l run my code to add a record in the database table l get the following error:
System.InvalidOperationException: 'Database provider factory not set for the static DatabaseFactory. Set a provider factory invoking the DatabaseFactory.SetProviderFactory method or by specifying custom mappings by calling the DatabaseFactory.SetDatabases method.
In my BusinessLogik, the following is what l have done:
1) Suppliers Class
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.Common
Public Class Suppliers
#Region "variables"
Private dbs As Database
#End Region
#Region "Properties"
Public Property SupplierID() As Long
Public Property Company() As String
Public Property Contact() As String
Public Property Landline() As String
Public Property Mobile() As String
Public Property Physical_address() As String
Public Property Postal_address() As String
Public Property Vat_no() As String
Public Property UserID() As Integer
#End Region
#Region "Constructor"
Public Sub New(ByVal conn As String)
dbs = DatabaseFactory.CreateDatabase(conn)
End Sub
#End Region
#Region "Methods"
Public Function SaveSuppliers() As Boolean
Dim cmd As DbCommand = dbs.GetStoredProcCommand("sp_saveSuppliers")
dbs.AddInParameter(cmd, "@supplierID", DbType.Int64, SupplierID)
dbs.AddInParameter(cmd, "@company", DbType.String, Company)
dbs.AddInParameter(cmd, "@contact", DbType.String, Contact)
dbs.AddInParameter(cmd, "@landline", DbType.String, Landline)
dbs.AddInParameter(cmd, "@Mobile", DbType.String, Mobile)
dbs.AddInParameter(cmd, "@physical_address", DbType.String, Physical_address)
dbs.AddInParameter(cmd, "@postal_address", DbType.String, Postal_address)
dbs.AddInParameter(cmd, "@vat_no", DbType.String, Vat_no)
Try
Dim ds As DataSet = dbs.ExecuteDataSet(cmd)
Return MsgBox("Supplier saved successfully.", MsgBoxStyle.Information, "FinanceSys")
Catch ex As Exception
Return MsgBox(ex.Message, MsgBoxStyle.Information, "FinanceSys")
End Try
End Function
#End Region
End Class
2) App Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="BusinessLogik.My.MySettings.FINConnectionString" connectionString="Data Source=FINANCE-PC;Initial Catalog=financial;Persist Security Info=True;User ID=sa;Password=password" />
</connectionStrings>
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data"/>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>
Good people, kindly assist because l am stuck. Thank you.
Continue reading...
System.InvalidOperationException: 'Database provider factory not set for the static DatabaseFactory. Set a provider factory invoking the DatabaseFactory.SetProviderFactory method or by specifying custom mappings by calling the DatabaseFactory.SetDatabases method.
In my BusinessLogik, the following is what l have done:
1) Suppliers Class
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.Common
Public Class Suppliers
#Region "variables"
Private dbs As Database
#End Region
#Region "Properties"
Public Property SupplierID() As Long
Public Property Company() As String
Public Property Contact() As String
Public Property Landline() As String
Public Property Mobile() As String
Public Property Physical_address() As String
Public Property Postal_address() As String
Public Property Vat_no() As String
Public Property UserID() As Integer
#End Region
#Region "Constructor"
Public Sub New(ByVal conn As String)
dbs = DatabaseFactory.CreateDatabase(conn)
End Sub
#End Region
#Region "Methods"
Public Function SaveSuppliers() As Boolean
Dim cmd As DbCommand = dbs.GetStoredProcCommand("sp_saveSuppliers")
dbs.AddInParameter(cmd, "@supplierID", DbType.Int64, SupplierID)
dbs.AddInParameter(cmd, "@company", DbType.String, Company)
dbs.AddInParameter(cmd, "@contact", DbType.String, Contact)
dbs.AddInParameter(cmd, "@landline", DbType.String, Landline)
dbs.AddInParameter(cmd, "@Mobile", DbType.String, Mobile)
dbs.AddInParameter(cmd, "@physical_address", DbType.String, Physical_address)
dbs.AddInParameter(cmd, "@postal_address", DbType.String, Postal_address)
dbs.AddInParameter(cmd, "@vat_no", DbType.String, Vat_no)
Try
Dim ds As DataSet = dbs.ExecuteDataSet(cmd)
Return MsgBox("Supplier saved successfully.", MsgBoxStyle.Information, "FinanceSys")
Catch ex As Exception
Return MsgBox(ex.Message, MsgBoxStyle.Information, "FinanceSys")
End Try
End Function
#End Region
End Class
2) App Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="BusinessLogik.My.MySettings.FINConnectionString" connectionString="Data Source=FINANCE-PC;Initial Catalog=financial;Persist Security Info=True;User ID=sa;Password=password" />
</connectionStrings>
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data"/>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>
Good people, kindly assist because l am stuck. Thank you.
Continue reading...