0

I am creating the following stored procedure (SP) from forms C# application:

string cmdText = @"CREATE PROCEDURE User_SelectOne as
                                SELECT * FROM Userinfo";

The ExecuteNonQuery command runs successfully and I am able to run and retrieve the SP results. However, if I open the MS Access database the newly created SP is not present. I have to create procedure every time I run the application, which means the SP object remains in working memory and not on disk. Is there a way to store the SPs created from code? The question described here does not describe the creation of the SP from C# and it does not demonstrate how to save the SP on the file.

Edi
  • 109
  • 11
  • Possible duplicate of [How do I make a stored procedure in MS Access?](https://stackoverflow.com/questions/3287545/how-do-i-make-a-stored-procedure-in-ms-access) – Jacob H Feb 19 '18 at 14:42
  • Dear @Jacob I saw that question. It does not give the solution to save the SP on the file – Edi Feb 19 '18 at 14:57
  • 3
    Maybe [you are overwriting your mdb file](https://social.msdn.microsoft.com/Forums/en-US/34396eb0-95f5-4286-bacf-837e5b455892/c-how-to-save-changes-in-dataset-to-mdb-file?forum=adodotnetdataproviders) when you start your program? – Crowcoder Feb 19 '18 at 14:57
  • @Crowcoder I opened the file during and after the program execution and the file is the same i.e. without the newly created SP – Edi Feb 19 '18 at 14:59
  • Is the data that you add/update/delete also gone next time you open it? – Crowcoder Feb 19 '18 at 15:03
  • No, the data and all the stored queries (using MS Access UI) are right into the place. That's what makes me confused – Edi Feb 19 '18 at 15:07
  • 1
    Your program is not using the same file that you are looking at. Check if you have the database file in the BIN\DEBUG folder or BIN\x86\DEBUG folder when you run the program inside Visual Studio, – Steve Feb 19 '18 at 15:33
  • Thank you @Steve. However how do use only one copy of the DB file and not recreate it every time you run the program? Or just use the file properties like "Do not copy" – Edi Feb 19 '18 at 15:54
  • You should set the property to copy if newer. More info here [Why saving changes to the database fails?](https://stackoverflow.com/questions/17147249/why-saving-changes-to-a-database-fails) – Steve Feb 19 '18 at 18:02

0 Answers0