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)

JJNL77
  • 159
  • 2
  • 3
  • 13
  • Please check your connection string [again](https://www.connectionstrings.com/sql-server/) – Trevor Mar 12 '21 at 13:01
  • 1
    Does this answer your question? [How can I set an SQL Server connection string?](https://stackoverflow.com/questions/15631602/how-can-i-set-an-sql-server-connection-string) – Trevor Mar 12 '21 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 '21 at 13:08
  • are you able to connect through SSMS using same connection string in question – TheGameiswar Mar 12 '21 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 '21 at 13:17
  • Even if the connection string is correct it doesn't mean the database is accessible over the network. Search your error, this question gets asked every day and you will find resources. – Crowcoder Mar 12 '21 at 13:17
  • Is `ULTRABOOK-JJ` the name of your own computer, the same one from which you're executing this code? Because the Named Pipes provider doesn't work across a network. – AlwaysLearning Mar 12 '21 at 14:16
  • It's indeed the same computer, so I have to use another server name? – JJNL77 Mar 12 '21 at 14:21
  • In your connection string replace "/" with "\".Not sure that you can use a user with a blank password for Windows authentication--you may have to create a password, and then use that password (or use SQL server authentication) – Tu deschizi eu inchid Mar 12 '21 at 20:51

0 Answers0