Home All Groups Group Topic Archive Search About

Problem Opening SQL Database

Author
3 Feb 2007 3:35 PM
Ken Ellis
I am new to SQL and I am having trouble connecting to a database using
SQLServer Express.
I have created the database ok and have used VS 2005 to create a drag and
drop program
(no manual code) to access it, but when I try to access it with the code
below I get the message

    "Cannot open database "MyDemo" requested by login. The login failed.
Login failed for 'Study\Ken' "

Its obviously to do with permissions but why should the generated program
work? I tried pasting the
connection string from the drag and drop config file into this program but
the errors I got made me realise
I was out of my depth.
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Data.SqlClient;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace WindowsApplication1

{

public partial class Form1 : Form

{

private static string conString =

@"Data Source=(local)\SQLEXPRESS; Initial Catalog=KensDemo; Integrated
Security=True";



public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

SqlConnection testConnection = new SqlConnection(conString);

SqlCommand testCommand = testConnection.CreateCommand();

testCommand.CommandText = "Select demoValue from Demo where demoID = 1";

testConnection.Open();

string result = (string)testCommand.ExecuteScalar();

testConnection.Close();

MessageBox.Show(result);

}

}

Author
3 Feb 2007 5:12 PM
David Browne
"Ken Ellis" <m***@kandmellis.plus.com> wrote in message
news:45c4abca$0$8746$ed2619ec@ptn-nntp-reader02.plus.net...
>I am new to SQL and I am having trouble connecting to a database using
>SQLServer Express.
> I have created the database ok and have used VS 2005 to create a drag and
> drop program
> (no manual code) to access it, but when I try to access it with the code
> below I get the message
>
>    "Cannot open database "MyDemo" requested by login. The login failed.
> Login failed for 'Study\Ken' "
> . . ..

This means Study\Ken does not have a Login in SQL Server and is not a member
of a group with a login.  If you are running on Vista without elevation,
your membership in BUILTIN\Administrators is supressed, and that can cause
this.  Otherwise get Management Studio for SQL Server Express and examine
the logins.  Make sure that Study\Ken has a login and is a member of the
sysadmin server role.

David
Author
4 Feb 2007 10:05 AM
Ken Ellis
Thanks David

It's working fine now.

Ken

Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:%23vGgEa7RHHA.1600@TK2MSFTNGP05.phx.gbl...
>
>
> "Ken Ellis" <m***@kandmellis.plus.com> wrote in message
> news:45c4abca$0$8746$ed2619ec@ptn-nntp-reader02.plus.net...
>>I am new to SQL and I am having trouble connecting to a database using
>>SQLServer Express.
>> I have created the database ok and have used VS 2005 to create a drag and
>> drop program
>> (no manual code) to access it, but when I try to access it with the code
>> below I get the message
>>
>>    "Cannot open database "MyDemo" requested by login. The login failed.
>> Login failed for 'Study\Ken' "
>> . . ..
>
> This means Study\Ken does not have a Login in SQL Server and is not a
> member of a group with a login.  If you are running on Vista without
> elevation, your membership in BUILTIN\Administrators is supressed, and
> that can cause this.  Otherwise get Management Studio for SQL Server
> Express and examine the logins.  Make sure that Study\Ken has a login and
> is a member of the sysadmin server role.
>
> David
>
>
>

AddThis Social Bookmark Button