SQLite database not persisting between sessions - sqlite

I working with a Windows Phone 8 application using
C#/XAML
SQLite v3.7.15
sqlite-net 1.0.7'
& Peter Huene's sqlite-net-wp8 (https://github.com/peterhuene/sqlite-net-wp8)
When debugging from VS I'm able to create a table, add data to the table and display the data in the UI. However, stop debugging and then resume the data from the last session is gone.
I create the connection like this
Connection = new SQLiteAsyncConnection("taskDB.db");
I'm not sure where that is putting the database?
I have tried the below so I could be sure where the database was being put but it results in the below error. I am surprised by this as I have seen this statement used in multiple examples.
_dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "taskDB.db");
Connection = new SQLiteAsyncConnection(_dbPath);
Which results in this error within SQLite.cs itself:
Error Message
SQLite.SQLiteException was unhandled by user code
HResult=-2146233088
Message=no such table: Tasks
Source=JustSQLite
Any idea why the database is not persisted between debug sessions?

The Emulator instance persists the changes till it is running.
Once you close the Emulator, the file will no longer persist as it is dependent on the Emulator instance

Related

Various difficulties creating ASP.NET Session tables via aspnet_regsql.exe

We're trying to move ASP.NET session state for one of our Azure web apps into a database, and it seems like the aspnet_regsql.exe tool is the way to go. Unfortunately, I'm getting stuck on a few issues below. It's an Azure SQL database, and I'm connecting using the server's admin account.
I initially wanted to add the session tables to our existing database, so I ran .\aspnet_regsql.exe -U adminusername -P adminpassword -S servername.database.windows.net -d databasename -ssadd -sstype c. Which throws the exception "Database 'databasename' already exists. Choose a different database name"
Omitting the database name and running it again throws the exception: "Execution Timeout Expired" after about 30 seconds, which is just the default for SqlCommand.CommandTimeout. This occurs while executing the "CREATE DATABASE" command. I tried creating a database manually, and it takes about 50 seconds for some reason. This database is S0 tier and is not under any load
Running aspnet_regsql again on the already-created database (because it's idempotent, right?) leads to the "Database already exists" error, as does pre-creating an empty database for it to start from.
There's no flag that lets me increase the timeout, and I can't set command timeout using the -C (connection string) flag
Adding the -sqlexportonly flag to generate a script and just running that directly doesn't work either (yes, I know I'm not supposed to run InstallSqlState.sql directly). It throws a whole load of error messages saying things like:
Reference to database and/or server name in 'msdb.dbo.sp_add_job' is not supported in this version of SQL Server.
USE statement is not supported to switch between databases.
Which makes me think this script might have some issues with an Azure SQL database...
Does anyone have any ideas?
Update:
It looks like all the errors involving 'msdb' are related to removing and re-adding a database job called 'Job_DeleteExpiredSessions'. Azure SQL doesn't support database jobs, so the only options I can see are
Run SQL on a VM instead (vastly more expensive, and I'd rather stick with the platform services than have to manage VMs)
Implement one of those "Elastic Job Agents"
Perhaps move the same functionality elsewhere (e.g. a stored proc)?
Turns out Microsoft has an article about how to do exactly what I need, which I somehow
missed during my searching yesterday. Hopefully this answer saves someone else a few hours of frustration. All the info you need is at https://azure.microsoft.com/en-au/blog/using-sql-azure-for-session-state/ earlier.
Note that YMMV since it's from 2010 and also says in scary red letters
"Microsoft does not support SQL Session State Management using SQL Azure databases for ASP.net applications"
Nevertheless, they provide a working script that seems to do exactly what I need.

Application services functionality lost in Azure

I have a ASP.NET application that uses application services to manage user roles. This application worked fine when I was using a local database. When I transitioned to Azure, the main data tables still work but I am unable have user's login or create new accounts because the Application table cannot be found. Previously, the application services created these tables automatically when using a local database. The connection string name appears accurate. This is my first attempt at Azure...is there something I'm missing?
The error is "The entity type Application is not part of the model for the current context"
For additional context: When I try to create the membership tables in the Azure database using aspnet_regsql.exe, I get the following error: "An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 40508 and the SqlException message is: USE statement is not supported to switch between databases. Use a new connection to connect to a different database."

Data is not coming from the database while running the windows phone 8 application

This is Basina, new to windows phone development.
I'm using SQLite in my Windows Phone8 Application following the below article.
http://www.developer.nokia.com/Community/Wiki/How_to_use_SQLite_in_Windows_Phone
When I debug the application I'm able to successfully created the database and tables.
After that i successfully installed the records into the table and retrieved the result and showed in a list.
After that I stopped the debugging of the application.
Now I run the application.
When I retrieve the data from the database and try to show the data in the list,
the list was empty i.e. data is not added to the list.
I didn't understand what was the problem.
While debugging the application everything goes fine, But while running the app i'm not getting data and also not showing any errors too.
I'm looking forward for your response.
Thanks & Regards,
Basina.
actually this is sqlite time connection issue. when you debug your app then thr is enough time for the sqlite to make successful connection but when you actually run this time is very less and when you made a query at that time the connection is not established so thr is no data in the list. so what you can do is..make the static connection at the start of your app and use this connection throughout app cycle .

Entity framework activates trigger to other database: error

I have a ASP.NET web application which does some changes on a table in SQL Server 2008 R2.
On this table there is a trigger that does updates on another table in another database on the same database server.
When saving the changes I'm having the following error:
- The error message: The underlying provider failed on Commit.
- InnerException: This SqlTransaction has completed; it is no longer usable.
Also allowing the database user to connect to the other database isn't working.
Somebody knows how I can make this work?
The trigger is not related to Entity Framework.
The trigger fires when changes are made to the table irrespective of where that change came from.
This is probably a rights issue, the system is attempting to make the change to the second database with the security context that was used to connect to the first database. It the change that was caused by the trigger fails, then everything in the same transaction will fail.
Since you are accessing 2 databases in a transaction, you are using MSDTC, make sure that it is started and that you have rights to it.

Deleting Database in Linq

In normal condition, I can add schemas in the dbml file to empty database with code below.
But now when I run this code, I take the error "Cannot drop database "test" because it is currently in use." How can I do it?
Dim db As New UI_Class.UIData
If db.DatabaseExists Then
db.DeleteDatabase()
End If
db.CreateDatabase()
It might happen as your SQL Server Management Studio (SSMS) must be holding it.
Most likely something is connected to the db.
Common causes are:
Some other tool connected
Trying to delete the database you connected to.
Another user connected to the db.

Resources