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)
- {
- SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
- scsb.DataSource = databaseServer;
- scsb.InitialCatalog = databaseName;
- if (databaseName == null || databasePassword == null)
- {
- scsb.IntegratedSecurity = true;
- }
- else
- {
- scsb.IntegratedSecurity = false;
- scsb.UserID = databaseUsername;
- scsb.Password = databasePassword;
- }
- SqlConnection SQLConnection = new SqlConnection(scsb.ConnectionString);
- try
- {
- SQLConnection.Open();
- }
- catch (Exception Ex)
- {
- // Tente de fermer la connexion, c'est nécessairement != NULL sinon le = new du dessus aurait planté
- SQLConnection.Dispose();
- // Crée un message d'erreur (utile)
- string ErrorMessage = "An 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