I have an exception every time I try to run my program without debugging (Ctrl+F5). The code seems to run fine with debugging. I have tried creating a temp project with just the essentials. I have reinstalled Visual Studio. The problem still occurs. There is already a post about this but not a clear answer.
My Connection String:
"Data Source=(localdb)\\ProjectsV12;Initial Catalog=gatdb;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Trusted_Connection=False;"
The Exception occurs here:
(SqlConnection connection = new SqlConnection(connectionString))
This is the exception:
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.SqlConnection..ctor(String connectionString, SqlCredential credential)
at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
at GatHunter.Sql.IsServerConnected(String connectionString) in c:\users\kold\documents\visual studio 2015\Projects\ScatteredGats\GatHunter\Sql.cs:line 14
at GatHunter.Program.Main(String[] args) in c:\users\kold\documents\visual studio 2015\Projects\ScatteredGats\GatHunter\Program.cs:line 14
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnectionFactory
StackTrace:
at System.Data.SqlClient.SqlConnection..cctor()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlPerformanceCounters
StackTrace:
at System.Data.SqlClient.SqlConnectionFactory..ctor()
at System.Data.SqlClient.SqlConnectionFactory..cctor()
InnerException:
BareMessage=Configuration system failed to initialize
HResult=-2146232062
Line=0
Message=Configuration system failed to initialize
Source=System.Configuration
StackTrace:
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
at System.Configuration.ConfigurationManager.PrepareConfigSystem()
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_SwitchSettings()
at System.Diagnostics.Switch.InitializeConfigSettings()
at System.Diagnostics.Switch.InitializeWithStatus()
at System.Diagnostics.Switch.get_SwitchSetting()
at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
at System.Data.SqlClient.SqlPerformanceCounters..ctor()
at System.Data.SqlClient.SqlPerformanceCounters..cctor()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Uri' threw an exception.
Source=System.Configuration
TypeName=System.Uri
StackTrace:
at System.Configuration.ClientConfigurationSystem..ctor()
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.UriParser' threw an exception.
Source=System
TypeName=System.UriParser
StackTrace:
at System.Uri..cctor()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Runtime.Versioning.BinaryCompatibility' threw an exception.
Source=mscorlib
TypeName=System.Runtime.Versioning.BinaryCompatibility
StackTrace:
at System.Runtime.Versioning.BinaryCompatibility.get_TargetsAtLeast_Desktop_V4_5()
at System.UriParser..cctor()
InnerException:
HResult=-2146233033
Message=Input string was not in a correct format.
Source=mscorlib
StackTrace:
at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
at System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent)
at System.Version.TryParseVersion(String version, VersionResult& result)
at System.Version.Parse(String input)
at System.Version..ctor(String version)
at System.Runtime.Versioning.BinaryCompatibility.ParseFrameworkName(String frameworkName, String& identifier, Int32& version, String& profile)
at System.Runtime.Versioning.BinaryCompatibility.ParseTargetFrameworkMonikerIntoEnum(String targetFrameworkMoniker, TargetFrameworkId& targetFramework, Int32& targetFrameworkVersion)
at System.Runtime.Versioning.BinaryCompatibility.ReadTargetFrameworkId()
at System.Runtime.Versioning.BinaryCompatibility.get_AppWasBuiltForFramework()
at System.Runtime.Versioning.BinaryCompatibility.BinaryCompatibilityMap..ctor()
at System.Runtime.Versioning.BinaryCompatibility..cctor()
InnerException:
In your connection string Integrated Security is set to False.
User ID = ****; Password = **** missing in your connection string.
If you would like to connect using Windows Authentication use
Integrated Security=SSPI; instead of Integrated Security=true;
If you try to use Integrated Security=true/false/yes/no with OleDb provider, you will get an exception during connection.
I want to thank everybody for their advise. I do not know why but what fixed this issue for me (even though I created an entirely new project and didn't touch the app.config) was this.
delete app.config
re-create via add->new item-> app.config
switch the target framework from 4.6.1 to 4.0 then back to 4.6.1
again.
Initially I wanted to see what the reaction was when I switched to the 4.0 framework and to my surprise it suddenly started working. I know this sounds strange and I have no explanation for it.
This mostly due an error in your app.config file, Check for badly formed XML or unexpected elements.
Also double check you connectionstring.
Try simplifying the connection string to;
string str="Data Source=(localdb)\\ProjectsV12;Initial Catalog=gatdb;Integrated Security=False;User ID=sa;Password=sa;";
SqlConnection connection = new SqlConnection(str);
and try again.
Do the following steps.
Create "xyz.udl" file on desktop.
Double click on that file.
Select appropriate provider
Select server
Set user / password and allow to save password
Select database and hit test connection.
Click on Ok button.
Open that "xyz.udl" file in notepad.
Copy your connection string and use that.
Related
This question already has answers here:
MSSQL Error 'The underlying provider failed on Open'
(31 answers)
Closed last year.
I have the following piece of code, which works at a customer, but not on my computer:
var result = await db.Configurations.FirstOrDefaultAsync().ConfigureAwait(false);
db is derived from a System.Data.Entity.DbContext, defined in EntityFramework.6.4.0\lib\net45\EntityFramework.dll.
In the corresponding SQL Server database, there is a table "Configurations" and it contains an entry.
When I launch the line of source code, an Exception gets generated (I hereby show the slightly formatted content of the immediate window while asking ? ex):
? ex
{"An exception occurred while initializing the database. See the InnerException for details."}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233087
HelpLink: null
InnerException: {"The underlying provider failed on Open."}
Message: "An exception occurred while initializing the database. See the InnerException for details."
Source: "EntityFramework"
StackTrace: " bij System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)\r\n bij System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
bij System.Data.Entity.Internal.LazyInternalContext.<>c.<InitializeDatabase>b__58_0(InternalContext c)
bij System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
bij System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
bij System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
bij System.Data.Entity.Internal.InternalContext.Initialize()
bij System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
bij System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
bij System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
bij System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
bij System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
bij System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source)
bij Project.<GetConfigAsync>d__56.MoveNext() in C:\\Source_Code_Directory\\Source_Code_File.cs:regel 2149"
TargetSite: {Void PerformInitializationAction(System.Action)}
I know this line of code works at customer's system, and I'm working on a restored backup of customer's DB.
What is going wrong and what can I do to fix it (what is the underlying provider)?
Thanks in advance
In the meantime the problem is analysed:
I had taken the backup of the customer's DB and restored it on my PC, but the username, as indicated in the connectionstring in source code, was wrong, hence my application could simply not open the database connection, so now the problem comes down on a database user management issue.
Thanks for all the support.
I get this onnx from Python but I received error in context.Transforms.ApplyOnnxModel() - "Unable to load DLL 'onnxruntime' or one of its dependencies: The specified module could not be found. (0x8007007E) where is a problem? What should I change?
error
'context.Transforms.ApplyOnnxModel(modelPath)' threw an exception of type 'System.TypeInitializationException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233036
HelpLink: null
InnerException: {"Unable to load DLL 'onnxruntime' or one of its dependencies: The specified module could not be found. (0x8007007E)"}
Message: "The type initializer for 'Microsoft.ML.OnnxRuntime.NativeMethods' threw an exception."
Source: "Microsoft.ML.OnnxRuntime"
StackTrace: " at Microsoft.ML.OnnxRuntime.SessionOptions..ctor()\r\n at Microsoft.ML.OnnxRuntime.InferenceSession..ctor(String modelPath)\r\n at Microsoft.ML.Transforms.Onnx.OnnxModel..ctor(String modelFile, Nullable`1 gpuDeviceId, Boolean fallbackToCpu, Boolean ownModelFile, IDictionary`2 shapeDictionary)\r\n at Microsoft.ML.Transforms.Onnx.OnnxTransformer..ctor(IHostEnvironment env, Options options, Byte[] modelBytes)\r\n at Microsoft.ML.Transforms.Onnx.OnnxTransformer..ctor(IHostEnvironment env, String[] outputColumnNames, String[] inputColumnNames, String modelFile, Nullable`1 gpuDeviceId, Boolean fallbackToCpu, IDictionary`2 shapeDictionary)\r\n at Microsoft.ML.Transforms.Onnx.OnnxScoringEstimator..ctor(IHostEnvironment env, String modelFile, Nullable`1 gpuDeviceId, Boolean fallbackToCpu, IDictionary`2 shapeDictionary)\r\n at Microsoft.ML.OnnxCatalog.ApplyOnnxModel(TransformsCatalog catalog, String modelFile, Nullable`1 gpuDeviceId, Boolean fallbackToCpu)"
TargetSite: {Void .ctor()}
TypeName: "Microsoft.ML.OnnxRuntime.NativeMethods"
I used before wrong tutorial this work correct https://learn.microsoft.com/en-us/azure/machine-learning/how-to-use-automl-onnx-model-dotnet
added parameters input and output
var onnxPredictionPipeline =
mlContext
.Transforms
.ApplyOnnxModel(
outputColumnNames: outputColumns,
inputColumnNames: inputColumns,
ONNX_MODEL_PATH);
and correct packages
dotnet add package Microsoft.ML
dotnet add package Microsoft.ML.OnnxRuntime
dotnet add package Microsoft.ML.OnnxTransformer
we are programming an multiplatform program with mono.
now i want to use some native code on a mac.
I found the NSLocal class and wanted to use:
string test = NSLocale.CurrentLocale.CountryCode;
but i run into an exception when the program is hitting this code:
Message: An exception of Type System.ArgumentNullException occured.
Message was: Value cannot be null. Parameter name: obj
Stacktrace:
at (wrapper managed-to-native)
System.Object:__icall_wrapper_mono_monitor_enter_v4_internal
(object,intptr) at ObjCRuntime.Runtime.TryGetNSObject (System.IntPtr
ptr, System.Boolean evenInFinalizerQueue) [0x00009] in
<1a80b695c02b4e7dbda63e331ae0ac27>:0
other code like:
string[] test2 = NSLocale.ISOCountryCodes;
also runs into an exception:
Message: An exception of type System.TypeInitializationException
occured. Message was: The type initializer for 'Foundation.NSString'
threw an exception.
Stacktrace:
at Foundation.NSArray.StringArrayFromHandle (System.IntPtr handle)
[0x00047] in <1a80b695c02b4e7dbda63e331ae0ac27>:0 at
Foundation.NSLocale.get_ISOCountryCodes() [0x00010] in
<1a80b695c02b4e7dbda63e331ae0ac27>:0
well what i'am doing wrong? when i'm calling this native code?
Thanks
i'm working with React.NET, i recently updated those nugets:
And now i receive this error :
Method not found: 'JavaScriptEngineSwitcher.Core.IJsEngine JSPool.IJsPool.GetEngine(System.Nullable`1<System.TimeSpan>)'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: Method not found: 'JavaScriptEngineSwitcher.Core.IJsEngine JSPool.IJsPool.GetEngine(System.Nullable`1<System.TimeSpan>)'.
Stack trace:
[MissingMethodException: Method not found: 'JavaScriptEngineSwitcher.Core.IJsEngine JSPool.IJsPool.GetEngine(System.Nullable`1<System.TimeSpan>)'.]
React.JavaScriptEngineFactory.GetEngine() +0
System.Lazy`1.CreateValue() +741
System.Lazy`1.LazyInitValue() +430
React.ReactEnvironment.EnsureUserScriptsLoaded() +40
React.ReactEnvironment.CreateComponent(String componentName, T props, String containerId, Boolean clientOnly) +43
Google didn't helped much, maby you can.
Thanks.
JavaScriptEnginerSwitch 2.0 is not supported yet: https://github.com/reactjs/React.NET/issues/319
and
https://github.com/reactjs/React.NET/issues/306
You will need to revert back to the previous version of those packages to get things working.
During development the program runs fine, but once published I noticed my elements weren't populating properly. I thought at first it was a problem with the update panels, but someone told me to use Firebug, and this is the error I see being thrown.
Again:
"Unable to connect to any of the specified MySQL hosts."
My code(This part is from the web.config):
<connectionStrings>
<add name="MySQLConnection" connectionString="[myServer];[myDatabase];UID= [myID];PWD=[myPassword];"
providerName="MySql.Data.SqlClient" />
</connectionStrings>
In C#, I call the connection string thusly:
string connstring = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MySQLConnection"].ConnectionString;
MySqlConnection myConnection = new MySqlConnection(connstring);
Any input on why this isn't working, or why it works in development and not once published, would be greatly appreciated.
Thanks.
EDIT: New information
Oh my god, this is maddening.
So my program had a second web.config file, and I had previously put a connection string in that one with incorrect data. When the program ran that's what it was trying to use, and that's why it wasn't working. Or so I thought.
I found this out, of course, after thinking it was the same file, and simply trying to update it. Finally I removed the connection string from the old file altogether, and what do you know, I now know that it's using the proper connection string.
Hoo-ray for me, right? Nope.
I now know that it is using the correct connection string, and yet it is still somehow not working.
That being said, I added some better troubleshooting in, so now I have this:
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Obj ect demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Net.Sockets.Socket.CheckCacheRemote(EndPoin t& remoteEP, Boolean isOverwrite)
at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state)
at System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state)
at MySql.Data.Common.StreamCreator.CreateSocketStream (IPAddress ip, Boolean unix)
at MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout)
at MySql.Data.MySqlClient.NativeDriver.Open()
The action that failed was:
Demand
The type of the first permission that failed was:
System.Net.SocketPermission
The Zone of the assembly that failed was:
MyComputer
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnecti onStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnecti on()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at WordsOfPower.testing.update_words() in C:\Users\AJ\documents\visual studio 2010\Projects\WordsOfPower\WordsOfPower\WordsOfPow er.aspx.cs:line 39
Final Edit: I updated my web.config to use full trust.
http://support.winhost.com/KB/a657/changing-the-default-aspnet-trust-level.aspx
Make sure the connection string in the web.config file is correct
<add name="STRING_CONNECTION" connectionString="Server=[SERVER];Database=[DATA BASE NAME];Uid=[USER];Pwd=[PASSWORD];" providerName="MySql.Data.MySqlClient"/>
That is a trust issue.
See http://www.marthijnvandenheuvel.com/2011/04/14/fix-net-4-socketpermission-for-mysql-driver-in-medium-trust/