GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Mar-2009, 21:57
BobLewiston BobLewiston is offline
Junior Member
 
Join Date: Nov 2008
Posts: 46
BobLewiston is on a distinguished road

SQL Server connection problem


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

Here’s the code I’m using:
PHP 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
PHP 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?
Last edited by LuciWiz : 16-Mar-2009 at 06:59. Reason: Please insert your Php code between [php] & [/php] tags
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to obtain SQL Server FullText Search service? BobLewiston MySQL / PHP Forum 0 08-Mar-2009 12:07
Named virtual host not working Johnnyrotton Apache Web Server Forum 4 04-Sep-2007 21:32
Microsoft SQL Server :: SQL Server message 241, state 1, severity 16 lyuboe MySQL / PHP Forum 0 11-May-2005 05:31
Apache2 config issues monev Apache Web Server Forum 2 28-Jun-2004 07:19
Can't view pages from another machine on the Intranet aevans Apache Web Server Forum 9 14-May-2004 03:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:51.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.