DbProviderFactory CreateConnection Fails for System.Data.SqlClient

  • Thread starter Thread starter dbasnett
  • Start date Start date
D

dbasnett

Guest
Here is the code to test with. Create a new Form, add a button and put this code in the button.

Dim dbf As Data.Common.DbProviderFactory
'
' uncomment one of the below dbf =
'
'this fails
'dbf = Data.Common.DbProviderFactories.GetFactory("System.Data.SqlClient")
'these work
'dbf = Data.Common.DbProviderFactories.GetFactory("System.Data.Odbc")
'dbf = Data.Common.DbProviderFactories.GetFactory("System.Data.OleDb")

Dim conn As Data.Common.DbConnection
conn = dbf.CreateConnection



The create connection only fails for SqlClient. The error is

System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnection
StackTrace:
at System.Data.SqlClient.SqlConnection..ctor()
at System.Data.SqlClient.SqlClientFactory.CreateConnection()
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\dewayne.basnett\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb:line 19
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.InvalidOperationException
HResult=-2146233079
Message=Failed to read the configuration section for enclave providers. Make sure the section is correctly formatted in your application configuration file. Error Message: Configuration system failed to initialize
Source=System.Data
StackTrace:
at System.Data.SqlClient.SqlConnection..cctor()
InnerException: System.Configuration.ConfigurationErrorsException
BareMessage=Configuration system failed to initialize
HResult=-2146232062
Line=0
Message=Configuration system failed to initialize
Source=System.Configuration
StackTrace:
at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
at System.Configuration.Internal.InternalConfigRoot.OnConfigRemoved(InternalConfigEventArgs e)
at System.Configuration.Internal.InternalConfigRoot.RemoveConfigImpl(String configPath, BaseConfigurationRecord configRecord)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Data.SqlClient.SqlConnection..cctor()
InnerException: System.Configuration.ConfigurationErrorsException
BareMessage=Unrecognized configuration section userSettings.
Filename=C:\Users\dewayne.basnett\AppData\Local\WindowsApplication1\WindowsApplication1.vshos_Url_odwpvb4iq0tpdwxwwhwkttkzifz10zja\1.0.0.0\user.config
HResult=-2146232062
Line=3
Message=Unrecognized configuration section userSettings. (C:\Users\dewayne.basnett\AppData\Local\WindowsApplication1\WindowsApplication1.vshos_Url_odwpvb4iq0tpdwxwwhwkttkzifz10zja\1.0.0.0\user.config line 3)
Source=System.Configuration
StackTrace:
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
InnerException:






"Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

- from former MSDN User JohnWein

SerialPort Info

Multics - An OS ahead of its time.

Continue reading...
 
Back
Top