I know there is so many similar questions but I searched for hours and I really couldn't make it work so I decided to ask.
My app.config
file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="PractiseCS"
connectionString="Server=.;Database=PractiseCS;Trusted_Connection=True;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
And in my code, I am trying to use this connection string
SqlConnection connection;
string connectionString;
public AllUsers()
{
InitializeComponent();
connectionString =
ConfigurationManager.ConnectionStrings["PractiseCS"].ConnectionString;
}
private void AllUsers_Load(object sender, EventArgs e)
{
DoTheThing();
}
private void DoTheThing()
{
connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand command = new SqlCommand("SELECT * FROM Users", connection);
SqlDataReader read = command.ExecuteReader();
while (read.Read())
{
ListViewItem LV = new ListViewItem();
LV.Text = read["Id"].ToString();
LV.SubItems.Add(read["Username"].ToString());
LV.SubItems.Add(read["Password"].ToString());
listView1.Items.Add(LV);
}
connection.Close();
}
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 SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
I want this program to run in other computers as well, so I didn't write my local address. But I couldn't make it work on this way either.