Hi Werner,

On Aug 28, 1:39 am, "Werner F. Bruhin" <[EMAIL PROTECTED]> wrote:
> Mike,
>
> Sent this a bit to quickly
>
>
>
> Mike wrote:
> > Hi,
>
> > I am working on a wxPython application that saves data to various
> > tables in our MS SQL Server 2000. I connect to one table and get data
> > using a session. This works great. I then do a session.close() and
> > then a conn.close() where conn = engine.connect().  This seems to work
> > as expected as well. The problem happens when I connect to the second
> > table. I get the data from the second table just fine, but when I try
> > to update it using my 2nd session object, I get the following error:
>

<traceback snipped>

> > To get the data, I do the following:
>
> > pref = session.query(Acct_Prefs).filter_by(empID=self.emp_id,
> > pref_name='last_payPeriod').first()
>
> > Then I change a value like this:
>
> > pref.pref_value = someValue
>
> > Finally, I do a session.flush() and session.commit(). I've tried using
> > just a commit(), but I get the same error. Since I can run this second
> > session by itself in IDLE, I think the 1st session or connection or
> > something is somehow messing up the second one. Any ideas on what is
> > going on would be great. I'm still pretty green with SA, by the way.
>
> > I am developing on Windows XP, Python 2.5.2 and using SqlAlchemy
> > 0.4.7. I can upgrade if you guys think that's the issue.
>
> I am no expert in SA, but I am converting my application over to it.
>
> Why are you closing the session?



As I walked in this morning, I realized that closing one session and
opening a second one was probably stupid. I was trying to avoid
mapping tables unless I needed them, but I think I'll just map all of
them.


>
> You can work with many tables and do all your queries all in the one
> session.
>
> self.session = Session()
> pref = self.session.query(db.Preferences).get(1)
> # change pref here
> self.session.commit()
>
> cellar = self.session.query(db.Cellar).get(1)
> # change cellar here
> self.session.commit()
>
> etc etc


Does this work for multiple databases? This particular program I am
working on will be connecting to 2 or 3 databases and a table or three
in each of those. I'm pretty sure I have to create separate engines
for each db and probably bind separate sessions for those.



>
> I think in most wxPython application you would create the session in
> wx.App.OnInit and close it in wx.App.OnExit.
>
> Should you package your application with py2exe you should probably
> include this in your OnExit method:
>
>             self.session.close_all()
>             self.engine.dispose()
>
> I was seeing that my application would hang on closing if I did not do
> this.  I am using Firebird SQL, it might be something to do with that db
> as I heard from others using SA that they did not see this problem.
>
> Werner

Thanks for the quick reply.

Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to