Service Windows + Ecriture en base SQL
Bonjour a tous
Je bloque sur un problème qui à première vu est simple, mais je n'arrive pas à trouver de solution.
Je souhaiterais créer un service windows qui écrit des lignes dans une base SQL.
Voici le code de service
Code:
1 2 3 4 5 6 7
|
protected override void OnStart(string[] args)
{
t = new Timer(30000);
t.Elapsed += TimerCallback;
t.Start();
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
private void TimerCallback(object sender, ElapsedEventArgs e)
{
String connectionString = ConfigurationManager.ConnectionStrings["BaseLocal"].ConnectionString;
SqlConnection dbConnection = new SqlConnection(connectionString);
Debut.Clear();
Debut.Add("Connection");
Util.writeTxt(Util.GetConfigurationValue("PathLog") + "log" + DateTime.Now.ToShortDateString().Replace("/", "") + ".log", Debut);
SqlCommand insertCommand = new SqlCommand();
insertCommand.CommandType = CommandType.StoredProcedure;
insertCommand.CommandText = "Import_Create_Assistance";
insertCommand.Connection = dbConnection;
insertCommand.Connection.Open();
Debut.Clear();
Debut.Add("Connection effectuée");
Util.writeTxt(Util.GetConfigurationValue("PathLog") + "log" + DateTime.Now.ToShortDateString().Replace("/", "") + ".log", Debut);
insertCommand.ExecuteNonQuery();
insertCommand.Connection.Close(); |
Connection String
Code:
1 2
|
<add name="BaseLocal" connectionString="Data Source=PC2005047\\SQL_LOCAL_2008R2;Initial Catalog=SuiviParcoursH;Persist Security Info=True;User ID=sa;Password=supersa" providerName="System.Data.SqlClient"/> |
Le service plante au niveau de l'ouverture de la connexion avec le message suivant "Échec d'instance."
Avez vous une idée car là je bloque complétement.
Merci
Cordialement