473,589 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server connection problem

93 New Member
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
  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. }
  15. // define SqlCommand command or command string that contains query
  16. string commandString = "SELECT * from <table name>";
  18. // define SqlDataAdapter data adapter using command string & connection object:
  19. SqlDataAdapter dataAdapter = new SqlDataAdapter (commandString, conn);
  21. // create new DataSet object (create DataSet)
  22. DataSet ds = new DataSet ();
  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. }
  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>"];
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\Tool s\Samples\Adven tureWorks 2008 OLTP or
C:\Program Files\Microsoft SQL Server\100\Tool s\Samples\Adven tureWorks 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 1951
2,878 Recognized Expert Specialist
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

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 tries to connect again. This of course all happens on the same machine (local connection only). The connections can come in as fast as 30+/sec, so the server is threaded (using SocketServer.ThreadingTCPServer). Further, the server initialization...
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 =================== From Visual Studio.NET 2003 I attempt to ‘Connect to a database’ The ‘Data Link Properties’ dialog box appears.
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 to test if a connection can be made to the local server. I can call that web service from any box on my network, and with the correct connection string, I can establish a connection to the database. However, when I copy the exact same service...
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 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any one tell me how to set TCP\IP connection protocol on server for particular instance. Becuase I think
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 (running on Win2K SP4) machine that we want to run on a Windows 2003 server machine and access it via our internal LAN. We have opened the firewall to allow our applications
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. My web server has both NTLM and Basic authentication. By providing the Credentials for my web service call, my application can access the web service without any problems. The problem: I recently created a new application with Visual Studio...
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 office. The original code's backend is using the SQL Server 2000 and I am testing to use it on the Express edition. And I run into the following problem.
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 the control unit and store them into the Sql server - The operation console then retrieve this data from the sql for reporting and statistics purposes - I am using ODBC connection - The problem is that the operation console is not able to...
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 ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
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 pass-through queries fail due to intermittent connection failures. I can easily restablish a connection for ADO. My problem is with pass-through queries.
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectóplanning, coding, testing, and deploymentówithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.