vb.netlinq-to-sqllocal-databasesubmitchanges

SubmitChanges() updates database in bin folder


My code and the Linq to sql function SubmitChanges are working, but when using a local database a copy of the database in the bin folder is updated and not the primary database. So the changes aren't shown on a new query. If I re-connect the database but don't load it as local same problem - the primary database isn't updated, but now I can't figure out which one is (tks to this question).

What setting for a local db or how do I use a non-local database to show changes on a new query of the database?

Dim DATA As New lnqPolarisDataContext
        Dim newBOOK As New BOOK()
        newBOOK.ID = 14
        newBOOK.LEG = 11
            newBOOK.P_C = "C"
            newBOOK.STRATEGY = "STRADDLE"
            newBOOK.STRIKE = 999
            newBOOK.CONTRACT = "XXX"

            DATA.BOOKs.InsertOnSubmit(newBOOK)
            DATA.SubmitChanges()

   ... new query doesn't show these changes

maybe this is the best method?


Solution

  • The real solution in my opinion would be to put your database on the server where it belongs - after all, SQL Server is a server-based solution, not a file-based "database".....

    1. install SQL Server Express (and you've already done that anyway)

    2. install SQL Server Management Studio Express

    3. create your database in SSMS Express, give it a logical name (e.g. YourDatabase)

    4. connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:

      Data Source=.\\SQLEXPRESS;Database=YourDatabase;Integrated Security=True
      

      and everything else is exactly the same as before...

    Also see Aaron Bertrand's excellent blog post Bad habits to kick: using AttachDbFileName for more background info.