Text Replacements - Connection String

Posted on 2007-07-26
Last Modified: 2010-05-18
I have a login screen which gives the user the option of changing the data source

"Data Source=(local);Initial Catalog=AquariusLive;User ID=Aquarius;Password=aquarius"

So if they type in ADAM it will pleace (local) with ADAM is there any easy way of doing this without breaking the string up
Question by:rocky050371
    LVL 18

    Expert Comment

    How about this.

    Dim MyString As String = "Data Source=(local);Initial Catalog=AquariusLive;User ID=Aquarius;Password=aquarius".Replace("(local)", TextBox1.Text)
    LVL 18

    Expert Comment

    You could put in some other match string other than (local) so that local could be used such as

    Dim MyString As String = "Data Source=(~MyDatabase~);Initial Catalog=AquariusLive;User ID=Aquarius;Password=aquarius".Replace("(~MyDatabase~)", TextBox1.Text)

    This would allow (local) to be used as a datasource.

    LVL 18

    Accepted Solution

    You could also do a further replace if you wanted to replace a few values

            Dim MyString As String = "Data Source=(local);Initial Catalog=AquariusLive;User ID=Aquarius;Password=aquarius".Replace("(local)", TextBox1.Text).Replace("AquariusLive", TextBox2.Text)

    Hope this helps,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now