Sqlite crashes on open - sqlite

I try to run some basic code to test Sqlite in y project and the project always stops/exits on the call to Open().
Then in the debug window, I see that "Activation of the Windows Store app 'f398a499-0092-462e-9b50-aab3651b4b69_kxamnsbhqvv2e!App' failed with error 'Windows was unable to communicate with the target application. This usually indicates that the target application's process aborted. More information may be available in the Debug pane of the Output window (Debug->Windows->Output)'."
Version of Microsoft.Data.Sqlite is 1.0.0
Version of Microsoft.NETCore.UniversalWindowsPlatform is 6.0.6
Here is my code :
SqliteEngine.UseWinSqlite3(); //Configuring library to use SDK version of SQLite
using (SqliteConnection db = new SqliteConnection("Filename=sqliteSample.db"))
{
db.Open();
var tableCommand = "CREATE TABLE IF NOT EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY AUTOINCREMENT, Text_Entry NVARCHAR(2048) NULL)";
var createTable = new SqliteCommand(tableCommand, db);
try
{
createTable.ExecuteReader();
}
catch (SqliteException e)
{
//Do nothing
}
}
Thanks

Changed the version of Sqlite to 1.1.1 and now it works.

Related

Xamarin.Forms Portable + Mono.Data.Sqlite.Portable

Good day to everyone,
I'm building an application in Xamarin.Forms Portable for iOS,Android,Windows Universal(10) .
I'm trying to use the Mono.Data.Sqlite.Portable, but I'm not able to create or connect to a local database, I've tried many solutions to fix the problem, but until now I dint find the solution..
The error is trow at "connection.open();"
The Code is :
var config = DependencyService.Get<DB.IConfig>();
var cnn = config.DirectoryDB;
using (var connection = new SqliteConnection("" +
new SqliteConnectionStringBuilder
{
DataSource = "URI=file::memory:",
Version=3,
}))
{
//connection.ChangeDatabase("hello.db");
connection.Open();
using (var transaction = connection.BeginTransaction())
{
var insertCommand = connection.CreateCommand();
insertCommand.Transaction = transaction;
insertCommand.CommandText = "CREATE TABLE TESTE(teste as varchar(10))";
insertCommand.ExecuteNonQuery();
transaction.Commit();
}
}
on the "DataSource" I've a local path, and other paths.
(Ex:. C:\Users\MyMachineName\AppData\Local\Packages\f736c883-f105-4d30-a719-4bf328872f5e_nh7s0b45jarrj\LocalState\hello.db)
The error is :
An exception of type 'System.NotImplementedException' occurred in Mono.Data.Sqlite.dll but was not handled in user code
Additional information: The method or operation is not implemented.
ImageError
Connection Extra Information
The last picture, it may give more information....
Thank you all in advance :)
I've found the solution,I hope it helps the people that may be looking for the same as I.
Just go to Nuget - And download the Portable.Data.Sqlite that relies on SQLitePCL (Latest version) .
This package (Portable.Data.Sqlite) it will use the connection and will create SqliteDataReader and other property's that we are used to use .
This will work on Visual Studio 2015 and the project must be in framework 4.51 +=
----Error Tips----
if you encounter this error : Cant use Temporary Database or Path, just download Sqlite.dll and place on the project BIN folder and System32/ SysWoW64 .

SQLite CreateTable<> Database that already exists is replaced

Database that already exists is replaced by calling the method CreateTable <> in SQLite for Windows 8, erasing all the lines and creating a new table. How can I solve? following code to analyze:
using(var db = new SQLite.SQLiteConnection(App.DBPath))
{
db.CreateTable<ListasEntid>();
if (db.ExecuteScalar<int>("select count(1) from ListasEntid")==0)
{
db.RunInTransaction(() =>
{
db.Insert(new ListasEntid() { Nome = "Lista", Eletros = "Teste" });
});
}
}
Not sure what language you are using, but if you can execute raw SQL then you can use the following syntax:
CREATE TABLE IF NOT EXISTS ListasEntid (nome text, eletros text);
This ensures that table ListasEntid exists without nuking any of your previous data.
Thank you for the attention, but the problem was not specifically CreateTable method, but in the application configuration in the application properties, Debug tab, in option start the box was marked, "Unistall and then re-install my packege", erasing all files always initializing the debug.

SQLITE_BUSY The database file is locked (database is locked) in wicket

I am doing a project in wicket
How to solve the problem.
I came across such a message:
WicketMessage: Can't instantiate page using constructor public itucs.blg361.g03.HomePage()
Root cause:
java.lang.UnsupportedOperationException: [SQLITE_BUSY] The database file is locked (database is locked)
at itucs.blg361.g03.CategoryEvents.CategoryEventCollection.getCategoryEvents(CategoryEventCollection.java:41)
public List<CategoryEvent> getCategoryEvents() {
List<CategoryEvent> categoryEvents = new
LinkedList<CategoryEvent>();
try {
String query = "SELECT id, name, group_id"
+ " FROM event_category";
Statement statement = this.db.createStatement();
ResultSet result = statement.executeQuery(query);
while (result.next()) {
int id = result.getInt("id");
String name = result.getString("name");
int group_id = result.getInt("group_id");
categoryEvents.add(new CategoryEvent(id, name, group_id));
}
} catch (SQLException ex) {
throw new UnsupportedOperationException(ex.getMessage());
}
return categoryEvents;
}
at itucs.blg361.g03.HomePage.(HomePage.java:71)
categories = categoryCollection.getCategoryEvents();
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
Sqlite allows only one writer to the whole database at a time and, unless you selected "WAL" journal mode, no reader while writing. Moreover unless you explicitly ask it to wait, it simply returns the SQLITE_BUSY status for any attempt to access the database while conflicting operation is running.
You can tell sqlite to wait for the database to become available for a specified amount of time. The C-level API is sqlite3_busy_timeout; I never used sqlite from Java though, so I don't know where to find it there.
(...) tell sqlite to wait for the database to become available for specified amount of time.
In order to do it from Java, run the following statement just like a simple SQL statement:
pragma busy_timeout=30000; -- Busy timeout set to 30000 milliseconds

"Unable to open database file" using SQLite on Windows Phone 7

I am using SQLite for Windows Phone 7 (http://sqlitewindowsphone.codeplex.com/) and I have done every steps from this tutorial (http://dotnetslackers.com/articles/silverlight/Windows-Phone-7-Native-Database-Programming-via-Sqlite-Client-for-Windows-Phone.aspx)
Then I try to make some simple application with basic features like select and delete. App is working properly till I want to make one of this operations. After I click select or delete, compiler shows me errors that he is unable to open database file...
I have no idea why?
I used the same Sqlite client, and had the same problem. This problem occurs because the sqlite try to create file in IsolatedFileStorage "DatabaseName.sqlite-journal" and it does not have enough permissions for that. I solved the problem, so that created "DatabaseName.sqlite-journal" before copying database to IsolatedFileStorage. Here's my method that did it:
private void CopyFromContentToStorage(String assemblyName, String dbName)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
string uri = dbName + "-journal";
store.CreateFile(uri);
using (Stream input = Application.GetResourceStream(new Uri("/" + assemblyName + ";component/" + dbName,UriKind.Relative)).Stream)
{
IsolatedStorageFileStream dest = new IsolatedStorageFileStream(dbName, FileMode.OpenOrCreate, FileAccess.Write, store);
input.Position = 0;
CopyStream(input, dest);
dest.Flush();
dest.Close();
dest.Dispose();
}
}
it helped me, and worked well.
hope this will help you
Are you sure the file exists?
You can check like that:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
exists = store.FileExists(DbfileName);
}

Simplest way to access a DB2 database on iSeries from a Linux (ubuntu) machine?

I would like to run an SQL query on an iSeries (...or "System i" or "AS/400"...) machine as part of a Nagios check, but haven't found a suitable way of interfacing the database yet.
IBM suggests using the ODBC driver of System i Access for Linux with unixODBC, but since both systems are new to me, I'd like to know if there are other ways of doing this.
Hacks involving telnet and expect are perfectly fine. :-)
I think this would be the simplest ...
Same as Access for Linux but it is the open source version: JTOpen
example taken from iSeries Information Center:
// Connect to the server.
Connection c = DriverManager.getConnection("jdbc:as400://mySystem");
// Create a Statement object.
Statement s = c.createStatement();
// Run an SQL statement that creates
// a table in the database.
s.executeUpdate("CREATE TABLE MYLIBRARY.MYTABLE (NAME VARCHAR(20), ID INTEGER)");
// Run an SQL statement that inserts
// a record into the table.
s.executeUpdate("INSERT INTO MYLIBRARY.MYTABLE (NAME, ID) VALUES ('DAVE', 123)");
// Run an SQL statement that inserts
// a record into the table.
s.executeUpdate("INSERT INTO MYLIBRARY.MYTABLE (NAME, ID) VALUES ('CINDY', 456)");
// Run an SQL query on the table.
ResultSet rs = s.executeQuery("SELECT * FROM MYLIBRARY.MYTABLE");
// Close the Statement and the
// Connection.
s.close();
c.close();
Found at Nagios Exchange:
DB2 Checker
Download DB2 Checker
untested...
I had this source on my disk. It's a good example. For clarity, I did change the machine, catalog and table name in the source. Hope it helps. It uses the JDBC driver from the JTOpen project.
Notice that with this specific driver you can access the iSeries DB2 database as any other database. Also, the DB2 database on the iSeries is just one of the versions of the IBM Universal Database. However, you can do iSeries specific tricks, even with the JDBC driver. But if you want to stay SQL defaults only, that is fine too.
import java.sql.*;
public class TestSQL {
public static void main(String[] args) {
try {
DriverManager
.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
Connection conn = DriverManager
.getConnection("jdbc:as400://YOURISERIES/YOURLIBRARY");
Statement select = conn.createStatement();
ResultSet rs = select.executeQuery("select * from whatever");
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
for (int x=1; x <= rsmd.getColumnCount(); x++) {
System.out.print(rs.getString(x));
}
System.out.println();
}
} catch (Exception e) {
System.out.println("error: " + e.getMessage());
}
System.exit(0);
}
}

Resources