C
C#17mo ago
Hudrel

✅ Get data from a BDD in C# WPF

Hello, i'm trying to get data from a SQL BDD and put it inside Label. I'm still having this error (sorry it's in french but you can translate it) : System.Data.SqlClient.SqlException : 'Une erreur liée au réseau ou spécifique à l'instance s'est produite lors de l'établissement d'une connexion à SQL Server. Le serveur est introuvable ou n'est pas accessible. Vérifiez que le nom de l'instance est correct et que SQL Server est configuré pour autoriser les connexions distantes. (provider: Named Pipes Provider, error: 40 - Impossible d'ouvrir une connexion à SQL Server)' I've tried to changer the server from 127.0.0.1 to localhost and it's still the same error. I've tried to open all connection to my SQL BDD still same. And here is my code : private void LoadDataFromDatabase() { string patchVersion = ""; DateTime date = DateTime.MinValue; string content = ""; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string query = "SELECT PatchVersion, Date, Content FROM patchnote"; SqlCommand command = new SqlCommand(query, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { patchVersion = reader.GetString(0); date = reader.GetDateTime(1); content = reader.GetString(2); } reader.Close(); } // Mettre à jour les labels dans la fenêtre WPF avec les valeurs récupérées NewPatchVersion.Content = patchVersion; NewPatchDate.Content = date.ToString("yyyy-MM-dd"); NewPatchContent.Content = content; } Hope it's a beginner issue x)
6 Replies
Hudrel
HudrelOP17mo ago
Oups, forgot to give you my connection string ^^ private static string connectionString = @"Server=127.0.0.1;Database=Test;User ID=UserTest;Password=wC/hn9DtRr[t7he(";
phaseshift
phaseshift17mo ago
Please don't post passwords etc Is also suggest you translate the error message
Hudrel
HudrelOP17mo ago
It's a fake password not the real one 🙂 Here is the traslated error : System.Data.SqlClient.SqlException: '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)'
Jimmacle
Jimmacle17mo ago
so your server isn't running at the address you put in your connection string
Hudrel
HudrelOP17mo ago
I don't understand because my server is running and i can access it 😒
Jimmacle
Jimmacle17mo ago
then it's probably a networking issue
Want results from more Discord servers?
Add your server