IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

C# Express 2010 - SQL Server 2008 Express Connection "Login failed"


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2011
    Messages : 5
    Par défaut C# Express 2010 - SQL Server 2008 Express Connection "Login failed"
    Dear all,

    I am really new to C# .NET and SQL Server, I usually manage to find all my informations thanks to existing posts, but I have to admit I'm actually stuck and a bit lost with all the resources available.

    I am actually developing a Windows Forms Application with Visual C# Express 2010 which would use (read/write) data from a SQL Server 2008 Express DB

    I have created my DB with SQL Server Management Studio (2008 Express), I understand the instance is named ATLELAG786576\SQLEXPRESS My DB is called 'TEST'

    Looking at my DB 'TEST' Properties in SQL Server Management Studio (2008 Express): Under Files, I am (ATLE\bneveux) the owner of the DB

    Looking under Security, Logins, Mylogin (ATLE\bneveux) My default DB is 'TEST' Server roles are 'public' + 'sysadmin' User Mapping DB 'TEST' User 'dbo' Default Schema 'dbo'

    In my C# application

    app.config:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <?xml version="1.0" encoding="utf-8" ?> <configuration>
        <configSections>
        </configSections>
        <connectionStrings>
            <add name="connectionStringTestDb"
                connectionString="Data Source=ATLELAG786576\SQLEXPRESS;Initial Catalog=D:\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\TEST.mdf;Integrated Security=True;Connect Timeout=30;User Instance=False"
                providerName="System.Data.SqlClient" />
        </connectionStrings> </configuration>
    dbConnection.cs:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    namespace SQLServerConnectionDemo
    {
        class dbConnection
        {
            public static SqlConnection newCon;
            public static string connectionStringTestDb = ConfigurationManager.ConnectionStrings["connectionStringTestDb"].ConnectionString;
            public static SqlConnection GetConnection()
            {
                newCon = new SqlConnection(connectionStringTestDb);
                return newCon;
            }
        }
    }
    dbAccess.cs:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    namespace SQLServerConnectionDemo
    {
        class dbAccess
        {
            SqlConnection conn;
            public dbAccess()
            {
                conn = dbConnection.GetConnection();
            }
            //Method insert new in tblEmployees
            public void addEmployee(string Id, string Name, string Email)
            {
                if (conn.State.ToString() == "Closed")
                {
                    conn.Open();
                }
                SqlCommand newCmd = conn.CreateCommand();
                newCmd.Connection = conn;
                newCmd.CommandType = CommandType.Text;
                newCmd.CommandText = "INSERT INTO tblEmployees VALUES ('"+ Id +"','"+ Name +"','"+ Email +"')";
                newCmd.ExecuteNonQuery();
            }
        }
    }
    in a form formEmployeeAdd.cs:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    namespace SQLServerConnectionDemo
    {
        public partial class formEmployeeAdd : Form
        {
            dbAccess access = new dbAccess();
            public formEmployeeAdd()
            {
                InitializeComponent();
            }
            private void btnInsert_Click(object sender, EventArgs e)
            {
                access.addEmployee(txtId.Text, txtName.Text, txtEmail.Text);
                MessageBox.Show("Data successfully added");
            }
        }
    }
    And here the error message i always get when trying to run this process:
    System.Data.SqlClient.SqlException (0x80131904): Cannot open database "D:\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\TEST.mdf" requested by the login. The login failed. Login failed for user 'ATLE\bneveux'.

    Note that I have never really been able to add my Data Source in Visual C# 2010 Express so I could manage the DB from VS, I always get the following error message:
    Unable to open the physical file "D:\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\TEST.mdf". Operating system error 32: "32(Le processus ne peut pas accéder au fichier car ce fichier est utilisé par un autre processus.)". An attempt to attach an auto-named database for file D:\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\TEST.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

    Thank you for your expertise

    Brice

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2011
    Messages : 5
    Par défaut
    Solved by changing
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Initial Catalog=D:\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\TEST.mdf
    to Thank you jeroenh
    http://stackoverflow.com/questions/1...n-login-failed

Discussions similaires

  1. [Débutant] Connexion VB 2010 Express à SQL Server 2008 Express
    Par 105rn2 dans le forum VB.NET
    Réponses: 39
    Dernier message: 05/01/2012, 08h17
  2. Souci avec Visual C# 2010 Express et SQL Server 2008 Express
    Par VILPELLET dans le forum Visual Studio
    Réponses: 5
    Dernier message: 13/09/2011, 19h20
  3. Réponses: 1
    Dernier message: 29/11/2009, 11h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo