|
-
January 18th, 2012, 08:45 AM
#1
Login failed for user ...
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"]);
}
}
}
}
-
January 18th, 2012, 11:59 AM
#2
Re: Login failed for user ...
When using trusted connection, I believe that implies Windows Authentication will be used. Is there an account on the SQL server with the same credentials as the local account you're logged in as and trying to run this code on?
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
-
January 18th, 2012, 02:27 PM
#3
Re: Login failed for user ...
I don't really understand what you mean, RaleTheBlade ... this is my PC, it is called MeDesktop, I am the only user defined on it, Gary, and I am an Administrator with full rights.
There is only one entry under Servers in the Server Explorer and that is MeDesktop.
Where else would I find other "Accounts" ?!?
If I remove the "Trusted_Connection = True" code, I get the same problem, but the Server is not identified, i.e. "Login failed for user ''."
-
January 19th, 2012, 12:30 PM
#4
Re: Login failed for user ...
This is now resolved, for anybody who wants to know, I had to change the SQLconnection to Browse for my database ... the whole resolution is here : http://www.c-sharpcorner.com/Forums/...-for-user.aspx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|