❔ 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.
4 Replies
Are you using MS SQL Server?
No, i explain the situation. I m internship ina company with 0 dev, I'm the only dev and i should develop a invoice app for windows. The database is hosted on the shared server of the website
So i search a way for connect my app to the database and for test i want to connect my c# winforms app to xampp
Connect to Xampp...?
What do you mean by that?
Xampp is not a database
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.