Problème de connexion Visual C#2008 et SQL Server 2005 sous Vista
Bonjour/Bonsoir,
Voilà mon erreur :
"Impossible d'ouvrir la base de données \"TestBDD\" demandée par la connexion. La connexion a échoué. Échec de l'ouverture de session de l'utilisateur*'Users'."
Voici mon app.config :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="TestBDDConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TestBDD;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="Test.Properties.Settings.TestBDDConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\TestBDD.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration> |
Voici le code de connexion à la DB :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace Test
{
public static class ProcStock
{
public static List<MaListe> VoirMaListe()
{
List<MaListe> J = new List<MaListe>();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestBDDConnectionString"].ToString());
SqlCommand comm = con.CreateCommand();
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "VoirMaListe";
con.Open();
try
{
SqlDataReader r = comm.ExecuteReader();
while (r.Read())
M.Add(new ListeJeu(r.GetInt32(0), r.GetString(1)));
return M;
}
catch
{
throw new Exception("Erreur de lecture");
}
finally
{
con.Close();
}
}
}
public class MaListe
{
private int id;
private String nom;
public int Id
{
get { return id; }
}
public MaListe(int id, String nom)
{
this.id = id;
this.nom = nom;
}
}
} |
Il affiche l'erreur à con.Open();
Merci d'avance.