none
Can't connect to SQL Server database, visual studio and sql server on my computer RRS feed

  • Question

  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace Database
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void Button1_Click(object sender, EventArgs e)
            {
                string connetionString;
                SqlConnection cnn;
                connetionString = @"Data Source=N201462857\SQLEXPRESS";

                cnn = new SqlConnection(connetionString);
                cnn.Open();
                MessageBox.Show("Connection open ! ");
            }
        }
    }
    System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)'
    Friday, September 13, 2019 7:08 AM

Answers

  • Hi pavlob,

    Thanks for the feedback.

    If you used database in SQL server, you could find it in the following picture, such as Matserdetail and test2.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Decompressor Friday, September 13, 2019 7:59 AM
    Friday, September 13, 2019 7:54 AM
    Moderator

All replies

  • Hi pavlob,

    Thank you for posting here.

    I think your connection string has some problems. The normal connection string should be like the following:

    connectionString="Data Source=N201462857\SQLEXPRESS;Initial Catalog=your database name;Integrated Security=True;"

    Please add the database statement and Integrated Security.

    Try this to see if it works.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 13, 2019 7:35 AM
    Moderator
  • Where can I take database name?
    Friday, September 13, 2019 7:46 AM
  • Hi pavlob,

    Thanks for the feedback.

    If you used database in SQL server, you could find it in the following picture, such as Matserdetail and test2.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Decompressor Friday, September 13, 2019 7:59 AM
    Friday, September 13, 2019 7:54 AM
    Moderator
  • Thank you, it works!
    Friday, September 13, 2019 7:59 AM