Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Web;
- using System.Data;
- using System.Data.SqlClient;
- public static class SQL
- {
- // Connexion à la base de données
- public static void connexion_sql(string databaseServer, string databaseName, string databaseUsername = null, string databasePassword = null)
- {
- string ConnectionString = "Data Source=" + databaseServer + ";";
- ConnectionString += "User ID=" + databaseUsername + ";";
- ConnectionString += "Password=" + databasePassword + ";";
- ConnectionString += "Initial Catalog=" + databaseName;
- SqlConnection SQLConnection = new SqlConnection();
- try
- {
- SQLConnection.ConnectionString = ConnectionString;
- SQLConnection.Open();
- }
- catch (Exception Ex)
- {
- // Tente de fermer la connexion
- if (SQLConnection != null)
- {
- SQLConnection.Dispose();
- }
- // Crée un message d'erreur (utile)
- string ErrorMessage = "A error occurred while trying to connect to the server.";
- ErrorMessage += Environment.NewLine;
- ErrorMessage += Environment.NewLine;
- ErrorMessage += Ex.Message;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement