I create a class connection.cs in Models folder of my project.
and in the loading of my form i call the class but my class return an error.
information in connectionString are correct normaly
the code of my class :
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NetFr4.Models
{
public class Connection
{
private readonly string connectionString = "Server=127.0.0.1;Database=laravel;User ID=root;Password=;";
public void OpenConnect()
{
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
MessageBox.Show(connection.State.ToString());
}
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
}
the error :
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server cannot be found or is not reachable. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Unable to open a connection to SQL Server.