Gary Heath

Gary Heath

  • NA
  • 15
  • 14.2k

Login failed for user ...

Jan 18 2012 9:58 AM
I am very, very new to C# & VS2010 .net programming, and this is my first ever attempt at SQL, though I am an experienced Mainframe programmer & have done a bit of VB & VBA.

I have a single Form with a single ComboBox and I am trying to populate it via a new SQL Database upon entry. That is all it does at the moment, but I get the error "Cannot open database "KA_LC_Database" requested by the login. The login failed. Login failed for user 'MEDESKTOP\Gary'."

Can anybody tell me why I am getting this problem ?

In Server Explorer my Server is called MeDesktop, in SQL Server Management Studio my Server is named MEDESKTOP and the connection is MEDESKTOP\Gary. It says it is "Ready" & Authentication Method is "Windows Authentication".

Also in VS2010, in Server Explorer, under Data Connections, there are 2 entries, KA_LC_Database.mdf & medesktop.master.dbo, both of these have a little red cross on them that changes to something white & black if I expand them. 

I hope this information helps, here is ALL my code ...

[code]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;
using System.Data.SqlClient;

namespace KA_League_Cup
{
    public partial class KA_LC_Form1 : Form
    {
        public KA_LC_Form1()
        {
            InitializeComponent();
        }

        private void KA_LC_Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("Entering Form1 Code");

            KA_LA_comboBox1.Items.Clear();

            SqlConnection cs = new SqlConnection("SERVER=MeDesktop;DATABASE=KA_LC_Database;Trusted_Connection=True");
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM LEAGUES", cs);

            DataTable dt = new DataTable();

            da.Fill(dt); <<<--- I get the error here 

            for(int i=0; i < dt.Rows.Count; i++)
            {
                KA_LA_comboBox1.Items.Add(dt.Rows[i]["LeagueName"]);
            }
        }
    }
}[/code]

Answers (5)