© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
7 replies
zaendrick

❔ How to connect C# winforms to xampp with System.Data.SqlClient

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.
Capture.PNG
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

c# winforms size
C#CC# / help
9mo ago
C# WinForms Chat
C#CC# / help
2y ago
❔ Microsoft.Data.SqlClient.SqlException
C#CC# / help
3y ago
❔ Exporting data in c# winforms button goes wrong
C#CC# / help
3y ago