I'm using Factory model to determine at runtime what kind of database I'm
using and to get the connection string from app.config.
I'm using the "ConfigurationM anager " static class provided by .Net
framework 2.0.
I marked in the code where the error is. I repeat again, from a form
everithing is running properly only from a user control that reside in a
control library is the problem. It seems I have to declare somehow the
static method in the code .
because the ConfigurationMa nager is a static method I cannot use New....
If you want to help me
Create a control library and in it, a control and put this code and try to
execute and you can see the results I mean the error message.You have to add
reference to System.Configur ation.
Bellow is the code and App.Config.
Thank you very much !
Mihai
The code is :
Imports System
Imports System.Data
Imports System.Data.Com mon
Imports System.Configur ation
Public Class NrSystemForAcco unts
'Private gts As GenericDb.Gener icDbWrapper.Gen ericTableServic es
Private dt As DataTable
Private mConnectionStri ng As String
Private mFactoryName As String
Private mFactory As DbProviderFacto ry
Private mFactoryConnect ion As DbConnection
Private mFactoryCommand As DbCommand
Private mDataAdapter As DbDataAdapter
Private Sub SetFactory(ByVa l DataBaseConnect ionName As String)
!!!!!!!! The error is in the line bellow :"Object reference not set to an
instance of an object"
mConnectionStri ng =
ConfigurationMa nager.Connectio nStrings(DataBa seConnectionNam e).ConnectionSt r
ing.ToString()
mFactoryName =
ConfigurationMa nager.Connectio nStrings(DataBa seConnectionNam e).ProviderName .
ToString()
mFactory = DbProviderFacto ries.GetFactory (mFactoryName)
End Sub
Private Sub NrSystemForAcco unts_Load(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
Me.SetFactory(" DatabaseConnect ion1")
End sub
End class
The App.config code is :
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<!-- This section defines the connections and database providers -->
<connectionStri ngs>
<add name="DatabaseC onnection1"
connectionStrin g="Persist Security Info=False;Inte grated
Security=SSPI;d atabase=Conta;s erver=(local);"
providerName="S ystem.Data.SqlC lient" />
<add name="DatabaseC onnection2"
connectionStrin g="" providerName="O racle" />
</connectionStrin gs>
<system.diagnos tics>
<sources>
<!-- This section defines the logging configuration for
My.Application. Log -->
<source name="DefaultSo urce" switchName="Def aultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSw itch" value="Informat ion" />
</switches>
<sharedListener s>
<add name="FileLog"
type="Microsoft .VisualBasic.Lo gging.FileLogTr aceListener,
Microsoft.Visua lBasic, Version=8.0.0.0 , Culture=neutral ,
PublicKeyToken= b03f5f7f11d50a3 a, processorArchit ecture=MSIL"
initializeData= "FileLogWri ter"/>
<!-- Uncomment the below section and replace APPLICATION_NAM E with the name
of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Di agnostics.Event LogTraceListene r"
initializeData= "APPLICATION_NA ME"/-->
</sharedListeners >
</system.diagnost ics>
</configuration>
"Mihai Velicu" <bv*****@telus. netwrote in message
news:ihCWg.6769 $P7.2840@edtnps 89...
Hi !
I created a class library and in it I have a class that call
"ConfigurationM anager" to find out what type of database I work and the
connection string.When I call this class from a form, everithing is
running
well, no errors.When I call this class from a custom control I receive the
message "Object reference not set to an instance of an object"
Does anyoane know what is happening ?
Thanks,
Mihai