Link to home
Start Free TrialLog in
Avatar of mpharis
mpharis

asked on

.NET 2.0 TableAdapterManager Does Not UPdating backend Database-I must be missing something basic

Very similar to post:  
https://www.experts-exchange.com/questions/23895093/TableAdapterManager-UpdateAll-does-not-save-dataset-to-database.html?sfQueryTermInfo=1

I'm building a Windows Application and attempting to migrate my skill-set from manually coding SQL Add/Update/Delete to using the databinding functionality in VS 2008. I have a small table of Users in SQL Server Express which I attempt to update from a form. The data changed are excepted on the screens and changes are redisplayed as I navagate away and back to the records again. Also, from debug, I can see the values in the DataSet are changing.
However, when I press the update button, and the TableAdapterManger.UpdateAll(me.DSusers) executes (no exeptions or errors) but the back end data base is unchanged. After reading several related issues I am:
Including a manual call to BindingSource.EndEdit()
If a duplicate set of data is being used in Debug, I can't find it.

Please Help me determine the problem so that I can move forward in my project.  
Try
            Me.UsersBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.DSusers)
        Catch ex As Exception
            MsgBox("Error on UPDATE - (" & ex.Message & ")")
        End Try
 
Connection String = Data Source=CDS001\ICEXPRESS;Initial Catalog=ICExpress;Persist Security Info=True;User ID=icexpress;Password=jack08;

Open in new window

Avatar of graye
graye
Flag of United States of America image

Take a look at the TableAdapter's properties....   you should be able to see the automatically-generated INSERT, DELETE, and UPDATE commands.
Also, if you're just using one table, you probably don't need to use the TableAdapterManager (as that was designed to perform the Update() method on each TableAdapter in the correct order... something that a bit of overkill if you've just got one TableAdapter).   So, just for the sake of simplifying your example, let's change that line to use the TableAdapter's update method.   It would look something like this:
     me.DSTableAdapter.Update()
... just guessing on the name of the TableAdapter!
Avatar of mpharis
mpharis

ASKER

Thanks, I'll give it a try later today and report the results. Thanks for the reply.
Avatar of mpharis

ASKER

ARGH!!!  This is very frustrating and I know I'm overlooking something simple.
I looked at the UPDATE commands in the properties of the TableAdapter and it looked fine. I replaced the TableAdapterManager with the TableAdapter and attempted an update. Still same results. Looks like good in the Application and Data set. I can advance to other records and them come back to the one I changed and it shows the changes. However, when I end DEBUG and the start the application again in DEBUG the changes are not there.  I just verified that when I execute the UPDATE command in the application, instead of exiting I when into the SQL Database and the backend data did not changed. I am not using a database file in the project/solution. I'm using a stand alone SQL Express database which exists outside of my project. I don't understand but is there any way that VS2008 is creating a temporary version of the database each time I enter debug and if so, how can I tell it or control it.  
Once again. Thanks in advance. Any info and/or direction you can give is greatly appreciated.  
Show us the generated connection string (also from the TableAdapter's properties), just to verify that VS2008 didn't somehow switch you over to a database file.
Avatar of mpharis

ASKER

Connection string from the tabeadapter propery:
Data Source=CDS001\ICEXPRESS;Initial Catalog=ICExpress;Integrated Security=True

I am manually resetting the connection string and loading the tableadapter in he Form Load event using the following code:
        stmnt = "SELECT userid, currentco, currentbu, admin, userDescription, createdtimestamp, " & _
            " defaultco, defaultbu, rrn, active FROM dbo.Users"
        DSusers.Clear()
        Dim DAusers As New SqlDataAdapter(stmnt, con)
        DAusers.Fill(DSusers, "Users")
        Me.UsersTableAdapter.Fill(Me.DSusers.Users)
This uses the connection string specified in the original post. It happens to be the same as the connection string property because this is the test sytem.
Looks like the only difference in the connection string is the change from integrated security to requiring credentials.





I think we're getting somewhere...   in the short example above, you're actually using two different techniques together...   the "traditional way" of using a DataAdapter to fill the table, but then you switch to using TableAdapters afterwards...    to fill the same table over again?
I'd suggest that  you stick to just one techique...
  • DataAdatper.Fill()
  • ... do something with the locally-cached DataSet
  • DataAdater.Update()
Avatar of mpharis

ASKER

That makes sense. How do I make the connection string dynamic for deployment to different clients and databases. My current technique (obiviously not fully tested) is to use the local database for development and call a custom class in the Page_Load event which retrieves the specific client connection string and attempts to re-bind/re-fill the datasets. That was my intended purpose above. What is the best way to make the application connection portable?
Most folk put the connection string in the web.config file.... that way you'd just have to change it in one place and the change would appear in all of the pages.
http://peterkellner.net/2008/02/23/webconfigbestpractice/ 
Avatar of mpharis

ASKER

Thanks for all the input graye. However, this is a windows form application so there is no web.config file and unfortunately the Connection String Application setting is "ReadOnly" so I can't dynamically change it there. Your input is much appreciated in this area but I suppose I need to get back to the focus of the original Post. I've tried going back to simply using the TableAdapter to update but still have the same results. DataSet gets updated in on screen but no Error messages or any indication of anything wrong but... backend data not updated.
I don't want to upload the whole VisualStudio solution/project; what can i provide to help nail down the issue. It is almost like the DataSet is not Bound to the backend database. I have relatively good confidence that the issue is not a copy or temporary database created at debug time. I've configured the application to display the connection info to the form at time of update and all looks well at that point.

I am attempting to reset the data connection to the client database like we discussed previously but have empoyed a different approach which fills the dataset and appears to be working fine (but again, this may be the area that's causing the problem)
Avatar of mpharis

ASKER

I removed any additional code and simply used the connection defined in the wizard with the table adapter. Same results. DataSet appears to update but database is unchanged.
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mpharis

ASKER

I appreciate your help mr. gray.  I'm not where i can look at this right now but will work through it over the week end. Please continue to check on my progress as you have time and i'll post results over the weekend. thanks