SQL Server connection problem - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Closed Thread
 
Thread Tools Display Modes
 
Old 03-15-2009, 10:06 PM   #1 (permalink)
Junior Techie
 
Join Date: Nov 2008
Posts: 91
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, 06:56 AM   #2 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
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, 11:57 AM   #3 (permalink)
Newb Techie
 
Join Date: Mar 2009
Posts: 17
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 Off


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



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 08:44 AM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.