﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Switching database connections</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 00:58:17 GMT</lastBuildDate><ttl>20</ttl><item><title>Switching database connections</title><link>http://forum.strataframe.net/FindPost23802.aspx</link><description>Is there a way to switch database connections such that I can jump from a development database to a production database, and back again?&lt;br&gt;
&lt;br&gt;
I know that I can remove the AppKeys.dat and Connections.dat files to remove the connections and then re-initialize via the Connection Wizard.  But this also wipes out all connections rather than a specific one.&lt;br&gt;
&lt;br&gt;
Thanks.</description><pubDate>Thu, 09 Jul 2009 15:27:20 GMT</pubDate><dc:creator>Doug Zapp</dc:creator></item><item><title>RE: Switching database connections</title><link>http://forum.strataframe.net/FindPost23808.aspx</link><description>Thanks Greg.&lt;br&gt;
&lt;br&gt;
Doug, glad it worked for you too!</description><pubDate>Thu, 09 Jul 2009 15:27:20 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Switching database connections</title><link>http://forum.strataframe.net/FindPost23807.aspx</link><description>Edhy,&lt;br&gt;
&lt;br&gt;
The only thing I'm adding is how to handle dirty forms automatically (i.e. skip the dialog). I test if it is dirty and then usually just undo (since this is used only the dev environment).  Hated clicking cancel 50 times....&lt;br&gt;
&lt;br&gt;
Doug,&lt;br&gt;
&lt;br&gt;
Glad you got it working! :D</description><pubDate>Thu, 09 Jul 2009 15:21:59 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Switching database connections</title><link>http://forum.strataframe.net/FindPost23806.aspx</link><description>So far I like Edhy's approach, which I've modified for my purposes.  I like this better because it gives me control ahead of time as to which environment I log into.  This code is added in my Program.cs file in ShowLoginAndInitMainForm method.  It will only fire if I'm running from VS.&lt;br&gt;
&lt;br&gt;
#if (DEBUG)&lt;br&gt;
            if (ConnectionManager.ShowAvailableConnectionStrings())&lt;br&gt;
                ConnectionManager.SetConnections();&lt;br&gt;
#endif&lt;br&gt;</description><pubDate>Thu, 09 Jul 2009 14:49:07 GMT</pubDate><dc:creator>Doug Zapp</dc:creator></item><item><title>RE: Switching database connections</title><link>http://forum.strataframe.net/FindPost23805.aspx</link><description>[quote][b]Greg McGuffey (07/09/2009)[/b][hr]I do something very similar.  The only thing I have added to this is a check to see if the form is dirty, with code to handle that situation. [/quote]&lt;br&gt;
Hi Greg,&lt;br&gt;
&lt;br&gt;
I am assuming that when calling form.Close() that if the form is dirty it will ask you if you want to save the changes.  I have not tested, but took that assumption for granted :P .  Can you please elaborate on why are you handling this?</description><pubDate>Thu, 09 Jul 2009 14:40:50 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Switching database connections</title><link>http://forum.strataframe.net/FindPost23804.aspx</link><description>I do something very similar.  The only thing I have added to this is a check to see if the form is dirty, with code to handle that situation. &lt;br&gt;
&lt;br&gt;
I allow this only for developers and it allows me to have multiple "dev" environments, as I can setup multiple connections, then just choose which I want.  E.g. I have a local connection, which attaches to a local db and I have a remote connection that attaches to a db in our data center.</description><pubDate>Thu, 09 Jul 2009 14:11:10 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Switching database connections</title><link>http://forum.strataframe.net/FindPost23803.aspx</link><description>Hi Doug,&lt;br&gt;
&lt;br&gt;
I use the following routine from a menu option so my users can change the database connection.&lt;br&gt;
[codesnippet]&lt;br&gt;
    Private Sub SetDatabaseConnection()&lt;br&gt;
        '-- Check security for this module&lt;br&gt;
        If Not CheckSecuritySecurityIsGranted("DatabaseConnection") Then&lt;br&gt;
            Exit Sub&lt;br&gt;
        End If&lt;br&gt;
&lt;br&gt;
        '-- Show the connection dialog and allow a connection to be selected&lt;br&gt;
        If MicroFour.StrataFrame.Data.ConnectionManager.ShowAvailableConnectionStrings() Then&lt;br&gt;
            '-- Since a connection was selected, then all of the existing dialogs need to be closed&lt;br&gt;
            '   since their connection is established to the original source.&lt;br&gt;
            For Each loForm As Form In Me.MdiChildren&lt;br&gt;
                loForm.Close()&lt;br&gt;
                loForm.Dispose()&lt;br&gt;
            Next&lt;br&gt;
&lt;br&gt;
            '-- Force the connections to be reset&lt;br&gt;
            MicroFour.StrataFrame.Data.ConnectionManager.SetConnections()&lt;br&gt;
&lt;br&gt;
        End If&lt;br&gt;
    End Sub&lt;br&gt;
[/codesnippet]</description><pubDate>Thu, 09 Jul 2009 13:21:44 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item></channel></rss>