Hello everyone,

Recently I tried to copy a database file onto my device but I'm getting some
null reference exceptions for some reason..
My code:

        public static SqliteConnection GetConnection()
        {
            var destPath = Path.Combine(

 System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
                     "items.db3");

            using (System.IO.Stream source =
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("items.db3"))
            using (var dest = System.IO.File.Create(destPath))
            {
                source.CopyTo(dest);
            }

            //var documents =
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            //string db = Path.Combine(documents, "items.db3");
            bool exists = File.Exists(destPath);
            if (!exists)
                SqliteConnection.CreateFile(destPath);
            var conn = new SqliteConnection("Data Source=" + destPath);
            if (!exists)
            {
                var commands = new[] {
"CREATE TABLE Items (Key ntext, Value ntext)",
"INSERT INTO [Items] ([Key], [Value]) VALUES ('sample', 'text1')",
                    "INSERT INTO [Items] ([Key], [Value]) VALUES ('sample2',
'text2')",
                    "INSERT INTO [Items] ([Key], [Value]) VALUES ('sample3',
'text3')",
};
                foreach (var cmd in commands)
                    WithCommand(c =>
                    {
                        c.CommandText = cmd;
                        c.ExecuteNonQuery();
                    });
            }
            return conn;
        }



My database file has the build action: "embedded resource" and the file name
is "items.db3"
How can I fix this?

Regards,
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to