0

I have used SQL management studio to create a database. Which connection string should I use now. Also the database does not appear in the Server object explorer why? I have worked in past on Dot Net this but I had never handled the database creation part myself. Please help. Thanks

My own attempt was:

 private void Form1_Load(object sender, EventArgs e)
        {    string constr = @"Data Source = Diabete; Initial Catalog = Cibi; Integrated Security = TRUE;";

            using (SqlConnection con = new SqlConnection(constr)){
                con.Open(); //here get error (cannot find server or database)
                using (SqlCommand cmd = new SqlCommand()) {
                    cmd.CommandText = "";
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    { }
                }
            }
        }
13
  • 1
    create a text file anywhere on your hard drive and call it test.UDL. Now doubleclick on it and a window should appear that helps you create a connection, complete with a test connection button Once the connection is working, open this file in notepad and there you see the connection string you can use Commented Apr 23, 2018 at 9:49
  • Is 'Diabete' your Server name ? Commented Apr 23, 2018 at 9:52
  • Diabate is the name of database Commented Apr 23, 2018 at 9:52
  • 2
    @user1238784 Then set Initial Catalog = Diabete and Data Source to server name (maybe ".", or ".\SQLEXPRESS" or whatever server name you connect to) Commented Apr 23, 2018 at 9:53
  • 1
    Diabete should be in initial catalognot in data source Commented Apr 23, 2018 at 9:54

1 Answer 1

1

you should put the database in initial cataglogand put the sql server name in Data Source

make a file with extension .UDLand doubleclick on it, set the properties like in this picture.

If you cannot choose your sql server in the top combobox then the sql server browserservice is not running on the machine where sql server is installed, or there is a firewall issue.

The sql server browser does not needs to be running to get it working, it only helps choosing the server if you dont know its name.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.