daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jun 4th, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Text;
  3. using System.Web;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6.  
  7. public static class SQL
  8. {
  9.  
  10.     // Connexion à la base de données
  11.     public static void connexion_sql(string databaseServer, string databaseName, string databaseUsername = null, string databasePassword = null)
  12.     {
  13.         SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
  14.         scsb.DataSource = databaseServer;
  15.         scsb.InitialCatalog = databaseName;
  16.         if (databaseName == null || databasePassword == null)
  17.         {
  18.             scsb.IntegratedSecurity = true;
  19.         }
  20.         else
  21.         {
  22.             scsb.IntegratedSecurity = false;
  23.             scsb.UserID = databaseUsername;
  24.             scsb.Password = databasePassword;
  25.         }
  26.  
  27.         SqlConnection SQLConnection = new SqlConnection(scsb.ConnectionString);
  28.  
  29.         try
  30.         {
  31.             SQLConnection.Open();
  32.         }
  33.         catch (Exception Ex)
  34.         {
  35.             // Tente de fermer la connexion, c'est nécessairement != NULL sinon le = new du dessus aurait planté
  36.             SQLConnection.Dispose();
  37.            
  38.             // Crée un message d'erreur (utile)
  39.             string ErrorMessage = "An error occurred while trying to connect to the server.";
  40.             ErrorMessage += Environment.NewLine;
  41.             ErrorMessage += Environment.NewLine;
  42.             ErrorMessage += Ex.Message;
  43.         }
  44.        
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top