none
VB.NET only seems to update the debug database, how do I have it make changes to the live one?

    Question

  • Hello everyone,

    I've created an application in <acronym title="Visual Basic">VB</acronym> .net to allow me to modify my student database, the problem being that it only updates the copy of the database in the debug folder.

    How can I make the program update the real database instead?


    Almost embarrassed to ask this one but I've been stumped for the past week!

    Oh, I'm using Visual Studio - <acronym title="Visual Basic">VB</acronym> .Net - 2010

    Love Alice
    Sunday, March 21, 2010 5:19 PM

Answers

  • Hi Alice,

    "In Visual Studio, there is an option to copy your database file to the output folder of your project. Usually this is done with an Access MDB file, or a SQL Server MDF file, when you add the database file to your project.

    This copy options applies each time you run the application. Therefore, although the database may in fact be updated, the updates are going to the copy instead of the original file that you expect. The key to this is the “Copy to Output Directory” property on the database file in your project. This is typically set to “Copy always” by default. What this means is that every time you build, run, or debug your application, Visual Studio copies the project file over to the output directory, and then that’s what the app connects to.

    In these cases, you will probably also be using a connection string that includes the "|DataDirectory|" option. For non-Web apps, this is the project output folder where your executable is created (usually bin\debug). In order to ensure that this connection string will work, Visual Studio chooses the "Copy Always" setting by default. You can keep the connection string as-is, but change the copy option to "Do not copy", and in that case, you should see your changes persist between application runs, or if you check the database outside of the app. Make sure to check the copy in the output folder. Alternatively, you can change the connection string *and* the copy property, and point to the file you actually want to connect to.

    This applies to Access MDB files, as well as SQL Server MDF files, as long as you are connecting to the MDFs file at runtime by specifying the location in the connection string with the AttachDBFilename keyword. Access databases are always file-based, so there is no need for a special keyword.

    There is a utility you can use to see which database file is actually being used by the application: FileMon by http://www.sysinternals.com. Start tracing before you run your application, then watch to see which file is actually accessed. Keep in mind that the trace may also include any file copies, so make sure you search for all occurrences of your filename, to be sure that all of them are using the file you expect."

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 23, 2010 10:48 AM

All replies

  • Hi Alice, If your working on Debug Mode that is the db that will be updated.

    So, if you want to update the release database you need to change the environment to Release Mode.

    Other way is to use an absolute path instead of using the application.startuppath.


    Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
    Si la respuesta te ha sido util Votala.
    Mi Blog: Jtorrecilla
    Enlace a Faq de Winforms en Ingles Muy bueno
    Sunday, March 21, 2010 5:28 PM
  • Hi Alice,

    "In Visual Studio, there is an option to copy your database file to the output folder of your project. Usually this is done with an Access MDB file, or a SQL Server MDF file, when you add the database file to your project.

    This copy options applies each time you run the application. Therefore, although the database may in fact be updated, the updates are going to the copy instead of the original file that you expect. The key to this is the “Copy to Output Directory” property on the database file in your project. This is typically set to “Copy always” by default. What this means is that every time you build, run, or debug your application, Visual Studio copies the project file over to the output directory, and then that’s what the app connects to.

    In these cases, you will probably also be using a connection string that includes the "|DataDirectory|" option. For non-Web apps, this is the project output folder where your executable is created (usually bin\debug). In order to ensure that this connection string will work, Visual Studio chooses the "Copy Always" setting by default. You can keep the connection string as-is, but change the copy option to "Do not copy", and in that case, you should see your changes persist between application runs, or if you check the database outside of the app. Make sure to check the copy in the output folder. Alternatively, you can change the connection string *and* the copy property, and point to the file you actually want to connect to.

    This applies to Access MDB files, as well as SQL Server MDF files, as long as you are connecting to the MDFs file at runtime by specifying the location in the connection string with the AttachDBFilename keyword. Access databases are always file-based, so there is no need for a special keyword.

    There is a utility you can use to see which database file is actually being used by the application: FileMon by http://www.sysinternals.com. Start tracing before you run your application, then watch to see which file is actually accessed. Keep in mind that the trace may also include any file copies, so make sure you search for all occurrences of your filename, to be sure that all of them are using the file you expect."

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 23, 2010 10:48 AM
  • Thanks Alex,

    I think I can remember it me now better.

    :-)

    Cor

     

    Tuesday, March 23, 2010 12:01 PM
  • You are welcome, Cor :)

    Best regards,
    Alex Liang

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 23, 2010 2:25 PM
  • Hello,

     

    I remember I solved this problem before but after formating my PC it seems I forgot the solution.

     

    I went through every file in solution explorer and changed the Copy to outlook directory to Do not copy.

     

    I didn't see any .mdf file there.

     

    Running the application on Debug or Release mode the database does not update at all. It used to work with the exact same code.

    How I am going to write to the original database and not to the copy of it?

     

    can you please help.

     

    thanks

     

    Tuesday, July 13, 2010 8:58 PM