Click here to Skip to main content
11,409,097 members (35,135 online)
   

C#

 
GeneralRe: Decrypt E-Mail address PinmemberMathlab20-Nov-12 9:55 
GeneralRe: Decrypt E-Mail address PinmemberMathlab20-Nov-12 9:14 
GeneralRe: Decrypt E-Mail address PinmvpDave Kreskowiak20-Nov-12 9:16 
GeneralRe: Decrypt E-Mail address PinmemberMathlab20-Nov-12 9:19 
AnswerRe: Decrypt E-Mail address Pinmemberharold aptroot19-Nov-12 23:53 
QuestionGet data back from windows process Pinmembertdcmystere19-Nov-12 3:42 
AnswerRe: Get data back from windows process PinmemberEddy Vluggen19-Nov-12 4:10 
GeneralRe: Get data back from windows process Pinmembertdcmystere19-Nov-12 4:19 
GeneralRe: Get data back from windows process PinmemberEddy Vluggen19-Nov-12 4:42 
GeneralRe: Get data back from windows process Pinmembertdcmystere19-Nov-12 5:17 
AnswerRe: Get data back from windows process PinmemberEddy Vluggen19-Nov-12 5:37 
GeneralRe: Get data back from windows process Pinmembertdcmystere19-Nov-12 6:21 
SuggestionRe: Get data back from windows process PinmemberEddy Vluggen19-Nov-12 6:25 
QuestionC# 2010 Express - SQL Server 2008 Express connection "Login failed" Pinmemberbneveux19-Nov-12 0:39 
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:
<?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:
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:
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:
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
AnswerRe: C# 2010 Express - SQL Server 2008 Express connection "Login failed" Pinmemberbneveux19-Nov-12 1:04 
QuestionWrite and read a paragraph in XML format string ? Pinmembertaibc18-Nov-12 17:29 
AnswerRe: Write and read a paragraph in XML format string ? Pinmembern.podbielski18-Nov-12 21:07 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembertaibc18-Nov-12 21:21 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembern.podbielski18-Nov-12 22:06 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembertaibc18-Nov-12 22:10 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembern.podbielski18-Nov-12 22:19 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembertaibc18-Nov-12 22:28 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembern.podbielski18-Nov-12 22:34 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembertaibc18-Nov-12 22:36 
AnswerRe: Write and read a paragraph in XML format string ? [modified] PinmemberPIEBALDconsult20-Nov-12 5:18 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembern.podbielski20-Nov-12 6:44 
GeneralRe: Write and read a paragraph in XML format string ? PinmemberPIEBALDconsult20-Nov-12 7:29 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembern.podbielski20-Nov-12 8:43 
GeneralRe: Write and read a paragraph in XML format string ? PinmemberPIEBALDconsult20-Nov-12 11:45 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembern.podbielski20-Nov-12 12:03 
GeneralRe: Write and read a paragraph in XML format string ? PinmemberPIEBALDconsult20-Nov-12 14:45 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembertaibc20-Nov-12 15:30 
GeneralRe: Write and read a paragraph in XML format string ? [modified] PinmemberPIEBALDconsult20-Nov-12 18:08 
GeneralRe: Write and read a paragraph in XML format string ? Pinmembertaibc20-Nov-12 18:33 
GeneralRe: Write and read a paragraph in XML format string ? PinmemberPIEBALDconsult20-Nov-12 19:08 
Question[Help] C# .txt Pinmembermumbot18-Nov-12 15:03 
AnswerRe: [Help] C# .txt PinmemberRags151218-Nov-12 19:30 
GeneralRe: [Help] C# .txt Pinmembermumbot18-Nov-12 20:43 
GeneralRe: [Help] C# .txt PinmemberV.19-Nov-12 1:37 
GeneralRe: [Help] C# .txt PinmemberPIEBALDconsult23-Nov-12 10:46 
AnswerRe: [Help] C# .txt Pinmemberomisheikh18-Nov-12 22:04 
GeneralRe: [Help] C# .txt Pinmembermumbot18-Nov-12 22:13 
GeneralRe: [Help] C# .txt Pinmemberomisheikh18-Nov-12 22:19 
GeneralRe: [Help] C# .txt Pinmembermumbot18-Nov-12 22:31 
GeneralRe: [Help] C# .txt Pinmemberomisheikh18-Nov-12 22:40 
GeneralRe: [Help] C# .txt Pinmembermumbot18-Nov-12 23:15 
GeneralRe: [Help] C# .txt PinmemberZac Greve18-Nov-12 23:32 
GeneralRe: [Help] C# .txt Pinmemberomisheikh18-Nov-12 23:34 
GeneralRe: [Help] C# .txt Pinmembermumbot19-Nov-12 1:02 
AnswerRe: [Help] C# .txt PinmemberMathlab19-Nov-12 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 25 Apr 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid