SQL Server CE Entity Framework code-first, the specified connection does not specify Initial Catalog or AttachDbFileName - ef-code-first

I have a desktop application that works with SQL Server CE and EF using a code-first approach, I have large volume of users working with this.
The connection string that I am passing to DbContext class constructor,
#"Data Source=" + Path.Combine("Path to local app data", "Databasename.sdf") + ";Password=mypassword"
But on one of the Windows 7 SP1 (32 bit) machines, I am getting following error:
System.InvalidOperationException: Unable to complete operation. The supplied SqlConnection does not specify an initial catalog or AttachDBFileName.
at System.Data.Entity.SqlServer.SqlProviderServices.GetOrGenerateDatabaseNameAndGetFileNames(SqlConnection sqlConnection, String& databaseName, String& dataFileName, String& logFileName)
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable1 commandTimeout, StoreItemCollection storeItemCollection) at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.MigrateDatabaseToLatestVersion2.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf1.b__e()
at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
at System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c)
at System.Data.Entity.Internal.RetryAction1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action1 action)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() at System.Linq.Queryable.Any[TSource](IQueryable1 source)
at GCMApiSDK.DataService.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at GCMApiSDK.AuthenticationDialog.<LoginButton_Click_1>d__11.MoveNext()
I am unable to figure out what is going wrong with that particular machine, because the same thing works for other Windows 7 users.
Plus I also tried re-installing SQL Server CE Runtime 3.5 SP2, but no luck.
To add more info, the database is successfully created in the specified location, but I'm unable to do other operations.

Related

ASP.NET Sharepoint CSOM error: An existing connection was forcibly closed by the remote host

I have an ASP.NET application running under .NET Framework 4.7.2.
In my application I am trying to connect to my Sharepoint site to create or rename folders.
Unfortunately I am getting below error.
I've been searching around on the internet and found a lot of articles talking about TLS but my application has TLS 1.2 by default due to the .NET Framework 4.7.2.
Does anyone would know the reason/background of the error?
(I don't have the error on my local machine (no SSL), error only occurs after deploying to my hosting environment with SSL)
This is the full error message:
Server Error in '/' Application.
An existing connection was forcibly closed by the remote host
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.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +106
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +130
[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +291
System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) +32
System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +156
System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +281
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +49
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +162
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +542
System.Net.TlsStream.CallProcessAuthentication(Object state) +42
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +228
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +21
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +64
System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +778
System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +52
System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +103
System.Net.ConnectStream.WriteHeaders(Boolean async) +388
[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
System.Net.HttpWebRequest.GetResponse() +1399
Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() +37
Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate() +514
Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() +126
Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() +44
Axius.Presentation.Website.frmAdminProjectDossierDetail.chkDossierSharepoint_CheckedChanged(Object sender, EventArgs e) in C:\inetpub\wwwroot\Axius.Presentation.Website\frmAdminProjectDossierDetail.aspx.cs:3637
System.Web.UI.WebControls.CheckBox.OnCheckedChanged(EventArgs e) +116
System.Web.UI.WebControls.CheckBox.RaisePostDataChangedEvent() +139
System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +12
System.Web.UI.Page.RaiseChangedEvents() +132
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1559
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3930.0
And this is the code:
using (ClientContext context = new ClientContext("https://mysite.sharepoint.com/"))
{
var passWord = new SecureString();
foreach (char c in "XXXXXXXXXX".ToCharArray()) passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("my#account.com", passWord);
List oList = context.Web.Lists.GetByTitle(#"Gedeelde documenten");
FolderCollection folders = oList.RootFolder.Folders;
context.Load(folders);
context.ExecuteQuery(); //this is frmAdminProjectDossierDetail.aspx.cs:3637 visible in the error
foreach (Folder folderr in folders)
{
if (folderr.Name == "01 PROJECTEN DOCS")
{
//code continues
}
}
}
There are at least two parts of a TLS connection: version and ciphersuites. You need to check the ciphers you have on your local machine:
https://learn.microsoft.com/en-us/powershell/module/tls/get-tlsciphersuite?view=windowsserver2022-ps
Then you should check the ciphers that are available on the sharepoint site:
https://www.ssllabs.com/ssltest/
At least one of the ciphers must match in order to complete the connection.

SQL1159 Initialization error with DB2 .NET Data Provider, reason code 10, tokens 0.0.0, 10.5.4, Process Owner: IIS APPPOOL\webapi

I am using IBM DB2 for LUW v10.5. webapi (ASP.NET application) is the name of the application hosted on IIS. Encountered below error when calling webapi methods.
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>The underlying provider failed on Open.</ExceptionMessage>
<ExceptionType>System.Data.EntityException</ExceptionType>
<StackTrace>
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) at System.Data.EntityClient.EntityConnection.Open() at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at WriteArrayOfPCMUSERToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , CollectionDataContract ) at System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph) at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content) at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Owin.HttpMessageHandlerAdapter.<BufferResponseContentAsync>d__27.MoveNext()
</StackTrace>
<InnerException>
<Message>An error has occurred.</Message>
<ExceptionMessage>
SQL1159 Initialization error with DB2 .NET Data Provider, reason code 10, tokens 0.0.0, 10.5.4, Process Owner: IIS APPPOOL\webapi
</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>
<StackTrace>
at IBM.Data.DB2.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn) at IBM.Data.DB2.DB2Connection.Open() at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
</StackTrace>
</InnerException>
</Error>
Detail explanation of SQL1159N can be found at below URL:
SQL1159N An error occurred during initialization of the IBM Data Server Provider for .NET. Reason Code: reason-code.
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.messages.sql.doc/com.ibm.db2.luw.messages.sql.doc-gentopic5.html#sql1159n
Here is snip of Explanation:
You can access the IBM database system with the IBM Data Server Provider for .Net.
This message is returned when there is a problem with the database product installation. This message can also be returned when the Windows extended security feature is enabled and the ID that is used to start the Internet Information Systems (IIS) service does not belong to the DB2ADMNS group or to the DB2USERS group.
The reason code for this message is intended for IBM support personnel only.
Hope this helps.

When using Scaffold-DbContext for UWP I get 'Unable to load DLL 'sqlite3''

I am trying to scaffolf an Entityframeworkcore DbContext for a UWP app from a Sqlite databse. I do:
Scaffold-DbContext "data source=C:\SqliteDbFiles\Sqlite.db" Microsoft.EntityFrameworkCore.Sqlite
No matter what I try though I keep getting this error:
System.DllNotFoundException: Unable to load DLL 'sqlite3': This operation is only valid in the context of an app container. (Exception from HRESULT: 0x8007109A)
at Microsoft.Data.Sqlite.Interop.NativeMethods.Sqlite3_sqlite3.sqlite3_open_v2(IntPtr filename, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
at Microsoft.Data.Sqlite.Interop.NativeMethods.Sqlite3_sqlite3.open_v2(IntPtr filename, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(String filename, Sqlite3Handle& ppDb, Int32 flags, String vfs)
at Microsoft.Data.Sqlite.SqliteConnection.Open()
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqliteDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.EntityFrameworkCore.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqliteScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ReverseEngineerImpl>d__21.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to load DLL 'sqlite3': This operation is only valid in the context of an app container. (Exception from HRESULT: 0x8007109A)
Any help would be greatly appreciated
The version of sqlite3.dll used at runtime on UWP won't work at design-time. You can manually download one of the Precompiled Binaries for Windows and copy it to the output directory (e.g. bin\x86\Debug) before running the command.
A simpler solution might be to scaffold the DbContext in a non-UWP project and just copy the classes into the UWP project after they're generated.

Oracle Managed DataAccess causes ORA-12537 Network Session: End of file

I could not create Oracle edmx in my asp.net solution when i use oracle.ManagedData access
Below is the stack trace, Please advice. I have also tried the solutions provided in ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file
[NetworkException (0x30f9): ORA-12537: Network Session: End of file]
OracleInternal.Network.ReaderStream.Read(OraBuf OB) +564
OracleInternal.TTC.OraBufReader.GetDataFromNetwork() +378
OracleInternal.TTC.OraBufReader.Read(Boolean bIgnoreData) +122
OracleInternal.TTC.MarshallingEngine.UnmarshalUB1(Boolean bIgnoreData) +43
OracleInternal.TTC.TTCProtocolNegotiation.ReadResponse() +212
[OracleException (0x80004005): ORA-12537: Network Session: End of file]
OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch) +7686
OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch) +1178
OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword) +1541
Oracle.ManagedDataAccess.Client.OracleConnection.Open() +3739
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +44
[EntityException: The underlying provider failed on Open.]
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +203
I have fixed this by recreating edmx with unmanaged driver instead of managed Driver. Application works perfect. !! used ODAC 12c Release 4.

Bonobo Can't Open Database File

I'm trying to install Bonobo on Windows 7/IIS 7/.Net 4.5 but I'm having trouble with SQLite. I get the following error when I load up the page in a browser
unable to open database file
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.Data.SQLite.SQLiteException: unable to open database file
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SQLiteException (0xe): unable to open database file]
System.Data.SQLite.SQLite3.Open(String strFilename, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, Int32 maxPoolSize, Boolean usePool) +731
System.Data.SQLite.SQLiteConnection.Open() +445916
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +102
[EntityException: The underlying provider failed on Open.]
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +11430327
System.Data.EntityClient.EntityConnection.Open() +142
System.Data.Objects.ObjectContext.EnsureConnection() +97
System.Data.Objects.ObjectContext.ExecuteStoreCommand(String commandText, Object[] parameters) +53
Bonobo.Git.Server.Data.Update.AutomaticUpdater.UpdateDatabase() +444
Bonobo.Git.Server.MvcApplication.Application_Start() +145
[HttpException (0x80004005): The underlying provider failed on Open.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12962661
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
[HttpException (0x80004005): The underlying provider failed on Open.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12979668
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12819261
I have SQLite installed now (though, I don't think that matters... Bonobo comes with its own SQLite dlls. I AM running on a 64 bit system. I don't know if that has anything to do with compatability. I've followed the installation instructions on the Bonobo site to the tee, but I still get this error and Google hasn't provided any answers for me. Could anyone point me in the right direction?
You should try to set the right security options for your IIS.
From http://bonobogitserver.com/install/

Resources