473,394 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. // define connection string for database server
  2. string connectionString = "server=<server name>; database=AdventureWorks; uid=<user name>; pwd=;";    // no password
  3.  
  4. // define SqlConnection connection to database using connection string
  5. SqlConnection conn = null;
  6. try
  7. {
  8.     conn = new SqlConnection (connectionString);
  9. }
  10. catch (Exception exc)
  11. {
  12.     MessageBox.Show (exc.Message, "conn = new SqlConnection (connectionString);");
  13. }
  14.  
  15. // define SqlCommand command or command string that contains query
  16. string commandString = "SELECT * from <table name>";
  17.  
  18. // define SqlDataAdapter data adapter using command string & connection object:
  19. SqlDataAdapter dataAdapter = new SqlDataAdapter (commandString, conn);
  20.  
  21. // create new DataSet object (create DataSet)
  22. DataSet ds = new DataSet ();
  23.  
  24. try
  25. {   // fill dataset object with query result via data adapter (for SELECT)
  26.     dataAdapter.Fill (ds, "<table name>");
  27. }
  28. catch (Exception exc)
  29. {
  30.     MessageBox.Show (exc.Message, "dataAdapter.Fill (ds, \"<table name>\");");
  31. }
  32.  
  33. // result of query now stored in dataset object in table "<table name>"
  34. // get reference to table by using indexer property of dataset object's Tables collection
  35. dataTable = ds.Tables ["<table name>"];
  36.  
At the statement
Expand|Select|Wrap|Line Numbers
  1. 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?
Mar 16 '09 #1
1 1940
ck9663
2,878 Expert 2GB
This is more of a question on your front-end app, not SQL server.


-- CK
Mar 16 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Fortepianissimo | last post by:
Here is the situation: I want my server started up upon connection. When the first connection comes in, the server is not running. The client realizes the fact, and then starts up the server and...
4
by: Frodo | last post by:
I have a problem establishing a link between Visual Studio.NET 2003 and SQL Server 2000. Both are installed on a Windows Server 2003, standard version. Visual Studio.NET Issues...
12
by: RKay | last post by:
I have a Win2k server running SQL Server 2000. On that box I built a working web service that pulls data from the database. One of the services available simply accepts an ado.net connection string...
0
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
3
by: Vinod R.Shenoy | last post by:
Hi All, Came across a post wherin you had helped somebody with a similar problem and was wondering if you could help us out with it. Our problem is , We have a development SQL Server 2000...
0
by: Kris Mattheus | last post by:
A little background: I've been using web services successfully for a while now. My web server is a Windows CE 4.2 device and my client is a windows C# application created with Visual Studio 2003....
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
5
by: marshmallowww | last post by:
I have an Access 2000 mde application which uses ADO and pass through queries to communicate with SQL Server 7, 2000 or 2005. Some of my customers, especially those with SQL Server 2005, have had...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.