0

I have tried to connect to my databse in sql server. My code is the following:

 private void button1_Click(object sender, EventArgs e)
        {
          
            SqlConnection cnn;
           string connetionString = "Server = ULTRABOOK - JJ/MSSQLSERVERML;" +
            "Initial Catalog = Research;" +
            "User id = ULTRABOOK-JJ/jurje;" +
            "Password = \"\";";

            cnn = new SqlConnection(connetionString);
            try
            {
                cnn.Open();
                MessageBox.Show("Connection Open ! ");
                cnn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

I get this error:

System.Data.SqlClient.SqlException (0x80131904): 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 the SQL server is configured to allow remote connections. (provider: Named Pipes Provide, error: 40 - Could not open a connection to SQL Server)

9
  • Please check your connection string again
    – Trevor
    Mar 12, 2021 at 13:01
  • 1
    Does this answer your question? How can I set an SQL Server connection string?
    – Trevor
    Mar 12, 2021 at 13:02
  • When I try: string connetionString = "Data Source= ULTRABOOK - JJ/MSSQLSERVERML;" + "Initial Catalog = Research;" + "User id = ULTRABOOK-JJ/jurje;" + "Password = \"\";"; it gives me the same error, and it has to be the right connection string
    – JJNL77
    Mar 12, 2021 at 13:08
  • are you able to connect through SSMS using same connection string in question Mar 12, 2021 at 13:17
  • 2
    A computer name cannot contain spaces and you cannot specify a Windows account user/password in the connection string. Determine you actual computer name (e.g. execute SET COMPUTERNAME from a command prompt) and change your connection string to be like "Data Source=YourActutalComputer\MSSQLSERVERML;Initial Catalog=Research;Integrated Security=SSPI"
    – Dan Guzman
    Mar 12, 2021 at 13:17

0

Your Answer

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

Browse other questions tagged or ask your own question.