1

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.

3
  • You can return JSON or even .3db file itself May 26, 2015 at 6:10
  • how can i achieve this when the db in in memory and no file asociated with it? May 26, 2015 at 6:12
  • You can store it temporary and return the file. Or you can convert your objects to JSON and return it as well May 26, 2015 at 6:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.