Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:54:00+00:00 2026-06-02T22:54:00+00:00

I am developing a program where I need to make a settings form for

  • 0

I am developing a program where I need to make a settings form for my database connection. I stopped at how to set the connection string from textboxes. Here is my code:

In the settings form:

public string adresa_servera()
        {    
            return textBox1.Text;
        }

The text in this textbox is: MICHAL-PC\SQLEXPRESS

In my main Form I use:

db_nastavenia nastavenia = new db_nastavenia(); //db_nastavenia is the name of the settings Form

string x = nastavenia.adresa_servera();

SqlConnection databaza = new SqlConnection();
databaza.ConnectionString = "Data Source=" + x + ";Initial Catalog=ZBERUDAJOVTEPLA;Persist Security Info=False;User ID=sa; password=diplomovka";

To x I load text from the textbox of the settings Form.

When I try it by manually typing the connection string like this, it works well:

databaza.ConnectionString = "Data Source=MICHAL-PC\\SQLEXPRESS;Initial Catalog=ZBERUDAJOVTEPLA;Persist Security Info=False;User ID=sa; password=diplomovka";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:54:02+00:00Added an answer on June 2, 2026 at 10:54 pm

    Michal, if this is the whole code and you don’t have set a default value for your textbox, it’s no surprise it isn’t working. You need to retrieve the value while reacting on some event, for example when you push some button… Or maybe monitor OnTextChanged event…

    This example shows you create some form and immediately try to retrieve a value. That won’t work, because the textbox has no value yet.

    Edit:
    Those double-double slashes are causing you these problems. Don’t know where it is applying this escaping logic, it may be some setting you set, but there’s an easy solution:

    string x = nastavenia.adresa_servera().Replace("\\", "\");
    

    Please let me know if this helped you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing program which need to interact with COM ports. By learning from
Im developing java program ,and I need to make it start working at each
I'm developing a PyQt program that will soon switch from an xml type backend
first question here. I'm developing a program in C# (.NET 3.5) that displays files
I'm developing a matlab program in which I uses polygons(concave or convex). I need
I am developing a program in which I need to generate a random number
So I'm developing my first iOS application and I need help.. Simple program for
I find myself needing a string table in a Haskell program I'm developing. In
In a program I am developing (Linux), I need very simple text-based IPC. It
I really need info about Nokia developing. Can I program Nokia (Symbian) devices only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.