locked
Forcing DB Changes to commit in SQL CE !!! RRS feed

  • Question

  • This is a really wide spread - more than a time discussed - on SQL CE MSDN Forums - Issue !!!

    Is there any way i can commit changes which happens during runtime (when i am developing the application) such as inserts/updates and deletes to the .sdf DB on the machine ?????

    Sunday, September 9, 2007 5:19 AM

Answers

  • You have several options to change this behavior. If your sdf file is part of the content of your project, this will affect how data is persisted. Remember that when you debug, all output of your project (including the sdf) if in the bin/debug folder.

    - You can decide not to include the sdf file as part of your project and manage the file location runtime.

    - If you are using "copy if newer", and project changes you make to the database will overwrite any runtime/debug changes.

    - If you are using "Do not copy", you will have to specify the location in code (as two levels above where your program is running).

    - If you have "Copy always", any changes made during runtime will always be overwritten

     

    Hope this assists.
    Sunday, September 9, 2007 8:08 AM

All replies

  • You have several options to change this behavior. If your sdf file is part of the content of your project, this will affect how data is persisted. Remember that when you debug, all output of your project (including the sdf) if in the bin/debug folder.

    - You can decide not to include the sdf file as part of your project and manage the file location runtime.

    - If you are using "copy if newer", and project changes you make to the database will overwrite any runtime/debug changes.

    - If you are using "Do not copy", you will have to specify the location in code (as two levels above where your program is running).

    - If you have "Copy always", any changes made during runtime will always be overwritten

     

    Hope this assists.
    Sunday, September 9, 2007 8:08 AM
  •  ErikEJ wrote:

    You have several options to change this behavior. If your sdf file is part of the content of your project, this will affect how data is persisted. Remember that when you debug, all output of your project (including the sdf) if in the bin/debug folder.

    - You can decide not to include the sdf file as part of your project and manage the file location runtime.

    - If you are using "copy if newer", and project changes you make to the database will overwrite any runtime/debug changes.

    - If you are using "Do not copy", you will have to specify the location in code (as two levels above where your program is running).

    - If you have "Copy always", any changes made during runtime will always be overwritten

     

    Hope this assists.
    Wednesday, September 24, 2008 10:32 AM
  • can enybody help me i am facing a problam to store signature into database i am working on divice appliction.

     

    when i input  fom the emulator it did not save in .sdf database and code did not give any error executenonquery returns 1 (one) row effected but database have not any data.

     

    when i input data into database by query (directly into database) data is inserted and display in appliction.

     

     

    sample of code

    i make a fuction to make a connection

    i try to make a connection in tow ways

     

    public static SqlCeConnection GetSqlCeConnection()

    {

     

     

    SqlCeConnection csconn = null;

     

     string cont = ("Data Source ="

    + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

     + "\\" + connection + ";"));

    string cont = @"Data Source =G:\signaturecontrol\Autograph\Autograph\SignatureDB.sdf;Persist Security Info=False;";

     cnMindNet = new SqlCeConnection(cont);

    this code gives error that while path is exist (i dont uderstand why this problem is occures)

     The path is not valid. Check the directory for the database. [ Path = signaturecontrol\Autograph\Autograph\Northwind.sdf ]

     

     

    other way to make connection

     

    String connString = Assembly.GetExecutingAssembly().GetName().CodeBase;

    connString = connString.Replace("Autograph.exe", "SignatureDB.sdf");

    cnMindNet = new SqlCeConnection(String.Format("Data Source={0}", connString));

    return cnMindNet;

     

    Dont give any error but when i open databse and do query nothing is srored in it

    }

    #endregion

     

    public void SetSign()

    {

    using (SqlCeConnection conn = GetSqlCeConnection())

    {

    if (conn.State == ConnectionState.Closed)

    {

    conn.Open();

    }

    SqlCeCommand cmd;

    string query = "insert into Signature (signName,signRegard,signSignature) values " +

    " ( @name,@regard,@sign )";

    //string query = "insert into Signature (signName,signRegard,signSignature) values ( '"+_name+"','"+_regards+"','"+_signature+"')";

    //SqlCeConnection con = new SqlCeConnection("server=bite11;database=SignatureDB;uid=geovision;pwd=ge0visi0n");

    //SqlConnection con = new SqlConnection("server=bite11;database=SignatureDB;uid=geovision;pwd=ge0visi0n");

    //con.Open();

    try

    {

    cmd = new SqlCeCommand(query,conn);

    cmd.Parameters.AddWithValue("@name", _name);

    cmd.Parameters.AddWithValue("@regard", _regards);

    cmd.Parameters.AddWithValue("@sign", _signature);

    cmd.ExecuteNonQuery();

    }

    catch (SqlCeException sqlexception)

    {

    sqlexception.Message.ToString();

    }

    catch (Exception ex)

    {

    ex.Message.ToString();

    }

    finally

    {

    conn.Close();

    }

     

     

     

     

     

     

     

     

    plz give the solution of this problem

    thanks.

    Wednesday, September 24, 2008 10:34 AM
  • Hi Erik

    Im new to Compact edition.
    I do have the same problem.

    I have my project in users\admin\desktop\mobileapp\test1\mydb.sdf

    An when im creating connectionstring  it was only allowing me to give the path for the emulator as
    program files\test1\mydb.sdf

    When I give the Project location above it was saying "Path incorrect"

    And finally it was not updating in the database though it was saying 1 record was updated. I even set the mydb.sdf properties to "do not copy" . But stiull it was not doing anything

      What do you mean by "specifythe location in your code as two levels above where your program is running" means  in your post

    Also how we can set relative path to the sdf file during runtime / debug time

    Regards Ben
    Monday, January 5, 2009 10:50 AM
  • Keep SDF File location same as your code location than your DLL/EXE location. 


    Please hit "Yes", if my post answered your question(s). All postings are as-is and confer no rights.
    Tuesday, January 6, 2009 6:08 AM
  • Hi
    Thanks for the quick reply.. I can explain a bit more clearly the file structure of my Smartdevice project. I have multiple mydb.sdf files creted and I dont know which one I should use.

    I had the Actual project in C:\users\admin\desktop\mobiapp\finaltest\(all.cs files..)

    C:\users\admin\desktop\mobiapp\finaltest\mydb.sdf

    C:\users\admin\desktop\mobiapp\finaltest\bin\Debug\finaltest.exe,finaltest--debugdatabase,mydb.sdf  -----  Here you can see mydb.sdf created during runtime


    In the Form1.load when I give the sql connection string ------------------
    Data Source="+ System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)+ "\\mydb.sdf"

    And it was reffering to C:\Program files\finaltest\mydb.sdf   If it dont find the database file here it was giving error database file was not found and asking me to verify the path. So just to make the applicaiton to work I created a directory in Program files as finaltest and copied the mydb.sdf there..

    So in this way I got mydb.sdf at 3 locations
    1. C:\users\admin\desktop\mobiapp\finaltest\mydb.sdf  Created during sqlserverCE new Connection which copies the DB file to local solution
    2. C:\users\admin\desktop\mobiapp\finaltest\bin\Debug\mydb.sdf (created by VS2008 during runtime along with finaltest.exe & otherfiles)
    3. C:\Program files\finaltest\mydb.sdf  (Created manually by me to make the applicaiton "Emulator" to run)
     In this way I got 3 mydb.sdf files and from the way I found from forum solutions I think through code

    it was commiting "
    C:\users\admin\desktop\mobiapp\finaltest\mydb.sdf " and during runtime it was overwriting that file

    with the DBfile present in"
    C:\Program files\finaltest\mydb.sdf "..  (It was just my assumption but no idea)

    I dont know where I was going wrong but the database is not getting updated at all though it was saying 1 record updated in the form.

    Also does the creation of DB file in ( "I mean copying into project") solution made all this confusion..

    After all the select command to show data from database is working fine


    Can any one help me with this issue .. Struggling from last one week

    If you dont understand what I wrote here you can mail me at jericosisters@gmail.com or post in the form. I will be 24/7  checking the forums for this problem

    Regards Ben

    Tuesday, January 6, 2009 10:40 PM
  •  
    Hi
     
    I am sitting with the exact same problem that other user's have here? I'm using the exact code I pull from literature to insert a record in Compact Edition but it just doesn't show up in the sdf database. Is there any other info you can provide to shed some light on the problem?
     
    I can retrieve data from the sdf database and store it in a dataset, insert new rows into the datatable/dataset, but as soon as I call the datatable update and stop the application, once I look in the database the added fields are not there. What could possibly be the problem
     
    Any help here will be greatly appreciated
     
    Regards
     
    Dieter


    __________ Information from ESET NOD32 Antivirus, version of virus signature database 3798 (20090125) __________

    The message was checked by ESET NOD32 Antivirus.

    http://www.eset.com/
    Wednesday, January 28, 2009 5:51 PM
  • Which SDF are you looking to, the one at the device, copying it back to your computer or openning it from SQL Server Management Studio via ActiveSync, or the one in your project solution?
    Alberto Silva Microsoft MVP - Device Application Development - http://msmvps.com/AlbertoSilva moving2u - R&D Manager - Microsoft Certified Partner - Mobility Solutions - http://www.moving2u.pt
    Thursday, January 29, 2009 10:22 AM
  • I am also having issues with getting SqlServerCe to update the sdf and I've tried the solutions proposed here with little effect on my problem.

    I have Visual Studio 2008 Express installed on XP-Pro and I'm trying to come up to speed on the C# language. I do program in other languages.

    Can someone point me to some reasonably complete sample code that uses SqlServerCe and a DataSet object to read, insert, update, and delete a Compact database?
    Thursday, March 26, 2009 12:23 AM
  • I have the same problem.  I cannot force changes to the sql ce database.   There must be a solution.   In my case, the application queries know what is in the database but DELETE and INSERT INTO do not work.   No errors are returned.   They just do not do anything.   The write number of rows affected is always returned.   By no action takes place.

    What is the solution?
    Thursday, March 26, 2009 3:04 AM
  • Problem Solved!

    My original location for the sdf file was in the shared directory of the Pocket PC.   Once i moved the sdf file to Program Files\... where my *.exe was located everything worked fine.  
    Thursday, March 26, 2009 4:18 PM
  • Hey, Did you find answer to your problem? I am having the same problem. Data is inserted in the table but it actually does not display when I click show table data. If you have got solution to this problem, can you please post it over here so that I can also resolve the issue. You can email me on chintan_shah8@yahoo.com

    Regards,
    Chintan
    • Proposed as answer by Chintan_Shah Friday, July 3, 2009 11:03 AM
    Thursday, July 2, 2009 5:42 AM
  • I too am having the same issue.

    Here is my code to update the table:

    Dim dTable As New PersonDataTable
    Dim dRow As PersonRow = dTable.NewPersonRow
    ... (setting the properties of the row)
    Dim rowsAffected As Integer = PersonTableAdapter.Update(dRow)

    rowsAffected = 1 after this command.

    Then I go and write another record to the database

    Dim dTable As New ResidenceDataTable
    Dim dRow As ResidenceRow= dTable.NewResidenceRow
    ...
    dRow.PersonID = (value of forign key to the table just created above)
    ...
    Dim rowsAffected As Integer = ResidenceTableAdapter.Update(dRow)

    When I try to create this table I get an error:

    A foreign key value cannot be inserted because a corresponding primary key value does not exist. [ Foreign key constraint name = Person To Residence ]

    The person table contains no foreign keys and is thus why I write to it first.

    Also, when I go to the debug folder and look at the sdf file nothing was written to the persons table. I've tried my sdf file as Copy if newer or Do Not Copy. It doesn't matter. The sdf file does not get updated even when I stop the code after the TableAdaper.Update command after it returns one. What the am I doing wrong?
    Sunday, July 5, 2009 10:14 PM
  • Has anyone found a solution to the problem where the data is not being written to the SQL CE database?

    The only time this is a problem for me is if the application ends abruptly it appears the last executenonquery has not been reflected in the SQL ce database, I have already confirmed the sdf file is in the same directory as the exe.

    This only thing that I can think is the table in the database is generated from an RDA pull and the table is tracked.
    • Proposed as answer by MD80study Saturday, February 20, 2010 10:03 PM
    Wednesday, August 5, 2009 3:59 AM
  • For those of you looking to fix this problem check out this thread http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/730a7b5c-df43-4f9f-9d1d-312659edc129

    Basically you can fix it be setting the new connection string option flush interval to 1, note flush interval not Flush Interval
    Wednesday, August 5, 2009 5:56 AM
  • I know the last post was 6 months ago, but I just came across this problem today and SOLVED IT!

    1) Your Db file has to be in the apps BIN/DEBUG folder.
    2) If you have any copies of the Db file in your application's other folders, delete them.
    3) In the IDE's DATABASE EXPLORER, if it is showing any reference(s) to any Db files, delete all
        of them.
    4) In the IDE's DATABASE EXPLORER click on "Connect To Database" button and make
        connection to your Db file that is in the BIN/DEBUG folder.
    5) Make sure your code's connection string points to the BIN/DEBUG Db file. I.E.:
        "Data Source = MyDb.sdf"

    That should do it!
    • Proposed as answer by Brett Donald Friday, January 21, 2011 4:50 AM
    Saturday, February 20, 2010 10:12 PM
  • private void button1_Click(object sender, EventArgs e)
      {
    
       SqlCeConnection conn = 
        new SqlCeConnection("Data Source='VolunteerDB.sdf';Persist Security Info=False;");
    
       SqlCeCommand cmd =
        new SqlCeCommand("INSERT INTO Task(taskID,taskName,taskDesc) VALUES(@id,@name,@desc)", conn);
    
    
       conn.Open();
    
       SqlCeParameter param0 = new SqlCeParameter("@id", SqlDbType.Int);
       param0.Value = 2;
       cmd.Parameters.Add(param0);
    
    
       SqlCeParameter param1 = new SqlCeParameter("@name", SqlDbType.NVarChar, 50);
       //param1.Value = txtTaskName.Text;
       param1.Value = "clean compound";
       cmd.Parameters.Add(param1);
    
    
       SqlCeParameter param2 = new SqlCeParameter("@desc", SqlDbType.NVarChar, 4000);
       //param2.Value = txtDesc.Text;
       param2.Value = "cleaning surrounding";
       cmd.Parameters.Add(param2);
    
    
       //SqlCeParameter param3 = new SqlCeParameter("@date", SqlDbType.DateTime);
       ////param3.Value = Convert.ToDateTime(txtdate.Text);
       //param3.Value = Convert.ToDateTime("2010/08/13");
       //cmd.Parameters.Add(param3);
    
    
       cmd.ExecuteNonQuery();
    
       conn.Close();
       MessageBox.Show("Task created successfully.");
      }

    I know the last post was 6 months ago, but I just came across this problem today and SOLVED IT!

    1) Your Db file has to be in the apps BIN/DEBUG folder.
    2) If you have any copies of the Db file in your application's other folders, delete them.
    3) In the IDE's DATABASE EXPLORER, if it is showing any reference(s) to any Db files, delete all
        of them.
    4) In the IDE's DATABASE EXPLORER click on "Connect To Database" button and make
        connection to your Db file that is in the BIN/DEBUG folder.
    5) Make sure your code's connection string points to the BIN/DEBUG Db file. I.E.:
        "Data Source = MyDb.sdf"

    That should do it!


    I've tried this. But it says my Database path incorrect.

    Here's my sqlceconnection:

    SqlCeConnection conn = new SqlCeConnection("Data Source=VolunteerDB.sdf");

    And here's my Error Message:
    The Database file cannot be found. Check the path to the database. [Data Source=VolunteerDB.sdf]


    I've deleted all the other .SDF files, except the last one is in "E:\Visual Studio\VMAnagement\VMAnagement\bin\Debug\VolunteerDB.sdf"

     

    I've tried "Data Source=.\VolunteerDB.sdf" but the error still occur.

    The message box pop up successfully if my connection string is


    "Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\\VolunteerDB.sdf;Persist Security Info=False;"

     

    But then, datagrid shows the new inserted record, but the actual record didn't update. when i restart the application, the data was not inserted.

     

     

    hope someone could guide. thanks

     

     

    Wednesday, May 12, 2010 5:36 AM
  • This is my data reader routine.  The variable mDataConn is the string  "Data Source= AviationQA_WGM.sdf"

    Private Sub ExecuteDataDbReader(ByVal strSQL As String)

     

        mSQLceCMD = New SqlCeCommand

        mSQLceCMD.Connection =

    New SqlCeConnection(mDataConn)

        mSQLceCMD.Connection.Open()

        mSQLceCMD.CommandText = strSQL

        mDataReader = mSQLceCMD.ExecuteReader(CommandBehavior.CloseConnection)

     

    End Sub

     

    I also found that I needed the database file to be in two locations.  The MD80/BIN/DEBUG folder and the folder two higher I.E. the "MD80" folder.

    I'm still not satisfied with my knowledge of CE's IO requirements, but for now this works.

    Hope this helps

    Friday, May 14, 2010 8:01 PM
  • I forgot to mention that you have to start the Visual Basic IDE in administrator mode to work with with the data bases.  Maybe this is your problem.  (If you're using some other IDE of Visual Studios' I suspect this will still be the case.)

    To start in administrator mode, right click on the IDE's shortcut, click on "Run as administrator" then "Continue".

    Good luck.

    Bill

    Sunday, May 16, 2010 4:41 PM
  • Thankyou so much! This issue has been annoying me for two entire days! And this was the answer.
    Friday, January 21, 2011 4:52 AM
  • Keep SDF File location same as your code location than your DLL/EXE location.


    Please hit "Yes", if my post answered your question(s). All postings are as-is and confer no rights.

    Could you explain it more clearly?
    Sunday, January 23, 2011 6:00 AM
  • I know the last post was 6 months ago, but I just came across this problem today and SOLVED IT!

    1) Your Db file has to be in the apps BIN/DEBUG folder.
    2) If you have any copies of the Db file in your application's other folders, delete them.
    3) In the IDE's DATABASE EXPLORER, if it is showing any reference(s) to any Db files, delete all
        of them.
    4) In the IDE's DATABASE EXPLORER click on "Connect To Database" button and make
        connection to your Db file that is in the BIN/DEBUG folder.
    5) Make sure your code's connection string points to the BIN/DEBUG Db file. I.E.:
        "Data Source = MyDb.sdf"

    That should do it!
    and do it it did! i've been cracking my head looking for workarounds or bugs or compatibility issues to solve this problem for the past 15 hours. thank you :)
    Tuesday, February 22, 2011 6:22 AM
  • Hi,

    I know this thread is quite old...

    But I am having the same issue.

    I followed the instructions here, to place the DB in the Bin/Debug folder and renewed the connection string.

    My DB is set to copy if newer , is this right?
    But my DB is still not getting saved I have a -1 in the AutoID column, which means its not saved and this is causing a concurrency violation on related records.

    It is only getting saved when I close and reopen which I don't know why it so.

     

    The way I save is typical,

     Try
          Me.Validate()
          ProjectBindingSource.EndEdit()
          ProjectDetailBindingSource.EndEdit()
    
          Me.TableAdapterManager.UpdateAll(Me.PTTDataSet)
          Me.ProjectDetailTableAdapter.Update(Me.PTTDataSet.ProjectDetail)
          ' Me.Form1_Load(sender, e)
    
          MessageBox.Show("Data Saved Sucessful!", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
        Catch ex As Exception
          MessageBox.Show("Data Failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    
    I would highly appreciate any help


    Abe Perl
    Monday, June 20, 2011 11:04 PM
  • Hi all,

    Many thanks to these special people!

    I was reffered by ErikEJ to a post on his site http://erikej.blogspot.com/2010/05/faq-why-does-my-changes-not-get-saved.html

    to this blog http://dean-o.blogspot.com/2010/03/mind-your-copy-to-output-directory.html

    Which Dean Willson reffered me to this excellent post by Beth Massi http://blogs.msdn.com/b/bethmassi/archive/2009/09/15/inserting-master-detail-data-into-a-sql-server-compact-edition-database.aspx

    This post by Beth gave me a clear view whats happening, and especially this part that I need to add a handler on the @@Identity column

    I hope this will help someone in need !

    Thank you guys, I love these forms where there is help on everything!

     


    Abe Perl
    • Proposed as answer by Abe Perl Thursday, June 23, 2011 3:31 AM
    Thursday, June 23, 2011 3:30 AM
  • H

    ello,
    Opening the topic again after so much time .I have the exact same problem, i tried everything that was mentioned here not nothing worked :(.


    Copy to Output is set to Copy if New (I also tried the other 2). My Connection is: _

     

    conn = new SqlCeConnection(@"Data Source=ToDo.sdf;Persist Security Info=False;");
    

     

    When I try to run an update or an insert query I got no errors and no exceptions at all. I even got a function for @@Identity: _

     

     

     private int GetIdentity()
            {
                object Id = null;
    
                cmd.CommandText = "Select @@IDENTITY;";
    
                if (cmd.CommandText.Length > 0)
                {
                    if (InTransaction && Transaction != null)
                    {
                        cmd.Transaction = this.Transaction;
                    }
                    Id = cmd.ExecuteScalar();
    
                }
    
                if (Id != null && Id.ToString().Length > 0)
                {
                    return Convert.ToInt32(Id);
                }
                else
                {
                    return 0;
                }
            }
    

     


    In fact when I try to insert that functions returns exactly the new ID number that it must have been. But after I commit the transaction in this function: _

     

    public virtual bool CommitTransaction()
            {
                if (Transaction != null)
                {
                    Transaction.Commit();
                    Transaction = null;
                    InTransaction = false;
    
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
    
                    return true;
                }
                else
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
    
                    InTransaction = false;
                    return false;
                }
    
            }
    

    I go and check the database but nothing happens, not even after I close and reopen again (even when I set the Copy to Output property to the other options).


    Anybody can tell me what am I missing here? Any help would be appreciated .Thanks

    Thursday, October 6, 2011 10:42 AM
  • Ok I think I got it now. Although I read all that was written above I had to try for myself and see what really happens. To be clear: _

    We have MyDataBase.sdf on MyProject, when we build the project another copy of MyDataBase.sdf goes to the Directory of bin\Debug and let’s call it MyDataBaseCopy.sdf. Know anything happens during runtime is being applied to MyDataBaseCopy.sdf not to MyDataBase.sdf.

    And as written above, when you set the Copy to Output Directory option to Copy if New, VS checks MyDataBase.sdf and compare it with MyDataBaseCopy.sdf. And if the first is newer it copies it to the second. Now I don’t get it, why? Why does it compare the old one with the newly created copy, and then if they are not the same it copies the old one to the new one’s place. Shouldn't be the opposite? And if so, why are the new values are written to the new one in the first place?

    Now if we choose Do Not Copy, the new Database (I mean the one in Bin\Debug folder) won’t be replaced by the old one at all, ok so how I can I access it? Simply by setting the connection string exactly to the Bin\Debug folder as “MD80study” wrote in his post. But we have to be careful not to ever set the database to copy if new or copy always or our New Database will be erased at first build !!.

    If we choose Copy Always, whatever we do in runtime will be replaced by the old (original) database after each Build to the Project.

    Did I understand it right? Am I missing something? Now if what I said above is right, all we need to do is setting the connection string directly to the Project folder using these methods :_

     

    Path.GetDirectoryName(Application.ExecutablePath);
    

     

    Which returns the executing Debug folder and then I substring it like this: _

     

    string FolderPath = appPath.Substring(0, appPath.IndexOf("\\bin"));
    

    And then adding the Database etc .The result have to look like this one :_

    "Data Source=D:\\Projects\\ExampleProject\\Forms\\MyDataBase.sdf;Persist Security Info=False"

    This is what the Connection String should look like ,note that Forms there is only the name of the Excutable Project .and that Copy To Output is set to Copy if New .  i Hope this was helping :)

    Thanks .



    • Edited by Naser Arab Friday, October 7, 2011 8:07 AM
    Friday, October 7, 2011 7:59 AM
  • Had this problem for some time and this is my solution, hope it helps someone. Maybe this is bad, so if anyone knows better then me ( Im new to c#) let me know.

    Go to Settings->Build->Outputh path -> erase everything ( check Configuration option on top, it must be on Debug).

    Now VS will not add \bin\Debug to your |DataDirectory|, and all changes you make to your DataBase will stay.

    Reason why I did not want to change connection string to full path, was that I was afraid that It would make problems once I want to deploy my program. Am I wrong with this one?
    Friday, February 17, 2012 7:33 AM
  • Hi all,

    Ive tried all these but couldnt get any answer. I am developing a windows mobile application and uses RDA to pull and push Tables from SQL Server to .sdf file(which is in the device). SELECT is working ,but INSERT,UPDATE,DELETE is not working.they execute,but no effect on the table.

    SQL Compact file path is      \Program Files\test.sdf

    this works with SELECT. 

    Wednesday, February 22, 2012 11:35 AM
  • Would you please try what i have suggessted 2 posts before ? Probably you are having the same thing i had when i first encountered this problem , check the connection string and the location of the Database during execution.
    Wednesday, February 22, 2012 11:40 AM
  • hi ,

    This path is fine for testing ,but when you remove the Mobile Device from the PC , this path doesnt exist.

    Mobile Device can refer to either \Program Files\Test.sdf    or  \Storage Card\Test.sdf       paths.

    how can we use these paths?

    Wednesday, February 22, 2012 11:58 AM
  • What is you connection string ? i mean how do you set it and what does it show during execution ?
    Wednesday, February 22, 2012 11:59 AM
  • Hi,

    I get the path from below code:

        Dim pathToDB As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

    then,

     pathToDB="\Program Files\TestMobDev"

    ("TestMobDev" is my project Name)

    .sdf file also located in root folder. (This path works for SELECT)

    and also i Checked .sdf file in the "bin\Debug\"  it also not Updated. 

    the "Copy to Out put Directory" property of the .sdf file is "Copy if Newer"

    • Edited by Ranjan.md Thursday, February 23, 2012 5:36 AM
    • Proposed as answer by KeyurPatel1 Wednesday, November 14, 2012 3:53 AM
    Thursday, February 23, 2012 3:25 AM
  • HI Ranjan250,

    I had the same issue. I could do select but not insert or update.
    My sdf file is located in the same directory as my windows form.
    After doing insert, whenever I checked sdf in the same directory as form, I could not see inserted record.
    It was because I should have been looking into sdf located in bin\debug instead.

    You need to make sure that your sdf in the same directory as win form, needs to set "Copy To Output Directory" To "Copy always".

    I can now see inserted record in the sdf in bin\debug file.

    Wednesday, November 14, 2012 3:54 AM