Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » SQL Server connection problem
Closed Thread
Old 03-15-2009, 11:06 PM   #1 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default SQL Server connection problem

I知 trying to learn how to connect to an SQL Server database (I知 using the AdventureWorks sample database), but I知 having problems.

Here痴 the code I知 using:
Code:
// define connection string for database server
string connectionString = "server=<server name>; database=AdventureWorks; uid=<user name>; pwd=;";    // no password

// define SqlConnection connection to database using connection string
SqlConnection conn = null;
try
{
    conn = new SqlConnection (connectionString);
}
catch (Exception exc)
{
    MessageBox.Show (exc.Message, "conn = new SqlConnection (connectionString);");
}

// define SqlCommand command or command string that contains query
string commandString = "SELECT * from <table name>";

// define SqlDataAdapter data adapter using command string & connection object:
SqlDataAdapter dataAdapter = new SqlDataAdapter (commandString, conn);

// create new DataSet object (create DataSet)
DataSet ds = new DataSet ();

try
{   // fill dataset object with query result via data adapter (for SELECT)
    dataAdapter.Fill (ds, "<table name>");
}
catch (Exception exc)
{
    MessageBox.Show (exc.Message, "dataAdapter.Fill (ds, \"<table name>\");");
}

// result of query now stored in dataset object in table "<table name>"
// get reference to table by using indexer property of dataset object's Tables collection
dataTable = ds.Tables ["<table name>"];
At the statement
Code:
dataAdapter.Fill (ds, "<table name>");
I'm getting the following error: "Login failed for user '<my user name>'."

As near as I can make out, the database AdventureWorks that I see in SQL Server 2008 Management Studio and that I'm trying to access resides at either C:\Program Files\Microsoft SQL Server\100\Tools\Samples\AdventureWorks 2008 OLTP or
C:\Program Files\Microsoft SQL Server\100\Tools\Samples\AdventureWorks OLTP.
I thought that maybe the problem was I was supposed to specify the full path name in the connection string, but that didn't help. Any suggestions?
BobLewiston is offline  
Old 03-16-2009, 07:56 AM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: SQL Server connection problem

can you login with management studio with username and no password?

sounds like permissions issue or wrong username // password
office politics is offline  
Old 03-17-2009, 12:57 PM   #3 (permalink)
 
Newb Techie

Join Date: Mar 2009

Posts: 17

racerx69 is on a distinguished road

Default Re: SQL Server connection problem

Did you setup your connection in SQL for your computer? I had some issues trying to execute the code to build the AW DB in SSMS 2008. Kept erroring all the time. Still cant get it to work.
racerx69 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection problems (malware related?) gold_leader64 Computer Networking & Internet Access 3 02-14-2009 11:20 PM
SSH Server Problem CalcProgrammer1 Computer Networking & Internet Access 0 12-02-2008 05:52 PM
SQL server removal superdave1984 Windows Operating Systems and Software 2 07-25-2008 11:22 AM
Hosting a Server W/ Wireless Connection commandercup Computer Networking & Internet Access 17 03-30-2008 03:13 PM