Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
| Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 31st, 2007, 09:24 PM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default changing connection string at runtime

I have created three different connection strings, based on server, and saved them into the application settings.
I can retrieve the settings with no problem.
What I can't figure out is how to replace the connection string in the table adapters in my data set with the correct one at runtime.

All of the examples I've seen show web-based applications, not a Windows form application and I'm new enough to VB2K5 programming to not always be able to convert what

I hope I'm making this clear enough. I really need help!

Thanks so much in advance! I know someone in this group has had to deal with this issue before.

Karen

  #2 (permalink)  
Old May 31st, 2007, 09:32 PM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default

I found my answer...

Me.EquipmentTableAdapter.Connection.ConnectionStri ng = APC_WirelessConnectionString

Hope this helps someone else.
(It still amazes me how quickly I figure my answer after I post a question on this forum.)

Karen

  #3 (permalink)  
Old July 3rd, 2007, 10:47 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default

Actually, I found another way to make this work for me.

from my main load routine
Code:
        My.Settings.ServerAlias = "SQLP1"

        Dim strComputerName As String = My.Computer.Name
        Dim strUserName As String = My.User.Name

        If (InStr(strUserName, "casek") And (strComputerName = "APC-WS01")) Then
            cmbServer.Enabled = True
            cmbServer.Visible = True
            btnOK.Enabled = True
            btnOK.Visible = True

            cmbServer.Focus()
        Else
            If InStr(strUserName, "Karen") Then
                My.Settings.ServerAlias = "APCD1"
            End If
        End If
the function that makes it all work ...
Code:
    Public Shared Function DetermineServer(ByVal strConn As SqlConnection) As String

        Dim strConnection As String
        Dim strServerAlias As String = My.Settings.ServerAlias

        If strServerAlias = "APCD1" Then
            strConnection = My.Settings.APC_WirelessConnectionString_Dvlp
        Else
            strConnection = My.Settings.APC_WirelessConnectionString_Prod
        End If

        Return strConnection
    End Function


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection String setting at runtime TwoTrees BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 3 July 2nd, 2010 11:41 AM
changing properties at runtime reza_ahmadi Java Espanol 0 December 26th, 2006 07:10 AM
Changing database at runtime joerage BOOK: Professional Crystal Reports for VS.NET 3 December 15th, 2006 05:55 PM
Specify the connection string property at runtime Lawrence C. Zauberis BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 1 July 7th, 2006 09:40 AM
Changing Stylesheet on runtime Thagi ASP.NET 1.x and 2.0 Application Design 2 February 17th, 2006 10:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.