1

Here is my Code:

private void button2_Click(object sender, EventArgs e)
    {

        SqlConnection connection = new SqlConnection("Data Source=DESKTOP-BPRGRPB/SQLEXPRESS;Initial Catalog=Test;Integrated Security=True");
        
                connection.Open();
                MessageBox.Show("connected!");
    }

I pulled the ConnectionString from the Server Explorer in VS2022. The following Error occurs after the ConnectionTimeout.

Microsoft.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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'

Inner Exception: Win32Exception: The network name cannot be found.

This is my first time using a database so I have no idea what I am doing. I just wanted to get it a shot and see if I could get a connection to a database running. I, also, tried using a SQLConnectionStringbuilder to make a Connection String with no luck.

I checked to setting is SQL Server Management Studio and remote connections are allowed.

Thanks for any help.

  • 1
    See if you can login to SSMS using `.\SQLEXPRESS` and if you can try using the following for your connection string in code `"Data Source=.\\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True"` – Karen Payne Jun 24 '22 at 23:07
  • Use the same server that is found on the SQL Server Management Studio login window. – jdweng Jun 24 '22 at 23:13
  • The following may be helpful: https://stackoverflow.com/questions/71198996/cant-access-my-sql-server-via-c-sharp-form-application-from-client-device/71199793#71199793 and https://stackoverflow.com/questions/71183112/oledb-sql-server-does-not-exist-or-access-denied/71187302#71187302 – Tu deschizi eu inchid Jun 24 '22 at 23:19
  • @KarenPayne Thank you. I uses / instead of \\. – Scott Sharpless Jun 24 '22 at 23:22

0 Answers0