lundi 25 mai 2015

export in-memory sqlite in C#

My Web Service are going to create in-memory sqlite from sql-server DB.

since i want my data not stored localy due to security restriction

im using in-memory method.

this my DB creator code :

    public ActionResult Get()
    {
        using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
        {  
            try
            {
                var sqlAdapter = new SqlDataAdapter("SELECT ID,Code,Name FROM UserDB", connection);
                DataTable table = new DataTable();
                sqlAdapter.AcceptChangesDuringFill = false;
                sqlAdapter.Fill(table);

                var sqlliteconnection = new SQLiteConnection("Data Source=:memory:;Version=3;New=True;");
                sqlliteconnection.Open();

                string sql = "create table UserDB(ID INTEGER,Code TEXT, Name TEXT)";

                SQLiteCommand command = new SQLiteCommand(sql, sqlliteconnection);
                command.ExecuteNonQuery();

                var sqliteAdapter = new SQLiteDataAdapter("SELECT * FROM Kiosk", sqlliteconnection);
                var cmdBuilder = new SQLiteCommandBuilder(sqliteAdapter);
                sqliteAdapter.Update(table);

                DataTable table_sqlite = new DataTable();
                sqliteAdapter.Fill(table_sqlite);

            }
            catch (Exception ex)
            {         
            }
        }
        return """My in-memory Database.3db """
    }

now i want to to get copy of in-memory db when i call the get() ActionResult.

Aucun commentaire:

Enregistrer un commentaire