Switching database connections


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Thanks Greg.



Doug, glad it worked for you too!

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Edhy,



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....



Doug,



Glad you got it working! BigGrin
Doug Zapp
Doug Zapp
StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)
Group: Forum Members
Posts: 39, Visits: 225
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.



#if (DEBUG)

if (ConnectionManager.ShowAvailableConnectionStrings())

ConnectionManager.SetConnections();

#endif

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Greg McGuffey (07/09/2009)
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.


Hi Greg,



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 Tongue . Can you please elaborate on why are you handling this?

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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.



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.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Doug,



I use the following routine from a menu option so my users can change the database connection.



Private Sub SetDatabaseConnection()

'-- Check security for this module

If Not CheckSecuritySecurityIsGranted("DatabaseConnection") Then

Exit Sub

End If



'-- Show the connection dialog and allow a connection to be selected

If MicroFour.StrataFrame.Data.ConnectionManager.ShowAvailableConnectionStrings() Then

'-- Since a connection was selected, then all of the existing dialogs need to be closed

' since their connection is established to the original source.

For Each loForm As Form In Me.MdiChildren

loForm.Close()

loForm.Dispose()

Next



'-- Force the connections to be reset

MicroFour.StrataFrame.Data.ConnectionManager.SetConnections()



End If

End Sub



Edhy Rijo

Doug Zapp
Doug Zapp
StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)StrataFrame Novice (101 reputation)
Group: Forum Members
Posts: 39, Visits: 225
Is there a way to switch database connections such that I can jump from a development database to a production database, and back again?



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.



Thanks.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search