Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
l am not a very good programmer but l have been using vb.net 2005 and now want to upgrade to vb.net 2017. l am using Microsoft enterprise library tools to work with stored procedures but each time l run my project to try and save a record in sql server 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.

l installed
Install-Package EnterpriseLibrary.Data -Version 6.0.1304
l am using three tier approach and here is what l have done in my BusinessLogik:

What I have tried:


1) Suppliers Class
Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.Common
Imports System.Data
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)
            MsgBox("Supplier saved successfully.", MsgBoxStyle.Information, "FinanceSys")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "FinanceSys")
        End Try
        Return True
    End Function
#End Region
End Class


2) app con
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="BusinessLogik.My.MySettings.FINConnectionString" connectionString="Data Source=FINANCE-SERVER;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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
  </startup>
</configuration>


Please assist and l would be happy if someone can also assist on the SaveSuppliers method. ls the last statement, "Return True" correct?? In my GUI project where l am calling the function l want to return the message.
Posted
Updated 27-Aug-20 22:55pm
v2

1 solution

Quote:
l would be happy if someone can also assist on the SaveSuppliers method. ls the last statement, "Return True" correct?

Well ... probably not.
Since it's the only Return statement in the whole method, it means that the outside world only ever gets True as a "result code". Which is rather silly when you think about it - why have a method that only evere returns the same thing regardless of what happens? It just means "there is no point in checking or otherwise dealing with what this method returns". If it fails and you get an exception, then perhaps it should return False to let the calling method know it didn't work properly and take appropriate action.

And if this is a three layer model app - and that's a good idea - why is a Data Layer method interacting with the user in any way at all? MessageBox is fine, but in a DataLayer you shouldn't "know" what kind of environment the Presentation Layer is working in, and MessageBox does not work in all environments. For example, in a Web based app, MessageBox shows at the Server, not the Client - so they both can;t see it or click the "OK" button!
Probably, you shouldn't be handling the exception at all, because you can't do anything with it that makes sense to the PL - so let it happen, and let the PL decide if it needs an Alert, a LoG2File, and / or a MessageBox.
 
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