Hi

On 2011.09.23 12:05, Mittchel Van Vliet wrote:
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?
Try putting it in Assets folder and load as asset....
Build action is Andorid asset!!

regards mel


Regards,


_______________________________________________
Monodroid mailing list
[email protected]

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


--
Miljenko Cvjetko dipl.ing. ET
        Direktor/CEO
        Projektant rjes(enja/Solution Architect 
        Razvojni programer/Senior developer
        Voditelj projekta/Project Manager

IX juz(na obala 13
Kajzerica Zagreb
T: 385 1 7775555
M: 385 91 557 447 3
F: 385 1 7779556
e: [email protected]
w: http://www.holisticware.net

_______________________________________________
Monodroid mailing list
[email protected]

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

Reply via email to