473,406 Members | 2,956 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,406 software developers and data experts.

new with c# and sql server 2005

am new with c# so plz be patient with me..
i have created a database and i wanna connect my application with it

while am searching i found this code:

using System;
using System.Data.SqlClient;

namespace ConsoleCSharp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class DataReader_SQL
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
try
{
SqlConnection thisConnection = new SqlConnection("Data Source=,1433;database=Database2;User id=;Password=;");
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisReader["CustomerID"], thisReader["CompanyName"]);
}
thisReader.Close();
thisConnection.Close();

}
catch (SqlException e)
{
Console.WriteLine(e.Message);
}

}
}
}

so my question is how can i change the user id and password i have tried to
add the password in the xml configuration file however i still have exception
plz help me out i wanna knew how can i connect my application with the
database using the connection string

thanks alot
Feb 8 '08 #1
6 1582
dip_developer
648 Expert 512MB
am new with c# so plz be patient with me..
i have created a database and i wanna connect my application with it

while am searching i found this code:

using System;
using System.Data.SqlClient;

namespace ConsoleCSharp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class DataReader_SQL
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
try
{
SqlConnection thisConnection = new SqlConnection("Data Source=,1433;database=Database2;User id=;Password=;");
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisReader["CustomerID"], thisReader["CompanyName"]);
}
thisReader.Close();
thisConnection.Close();

}
catch (SqlException e)
{
Console.WriteLine(e.Message);
}

}
}
}

so my question is how can i change the user id and password i have tried to
add the password in the xml configuration file however i still have exception
plz help me out i wanna knew how can i connect my application with the
database using the connection string

thanks alot
look here for connection string details...

http://www.connectionstrings.com/
Feb 8 '08 #2
dip_developer thanks a lot 4 ur reply

i have tried to use this one:
"Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"

however, i still have problem in opening the connection;

i just wanna knew if i can set up the user id and the password using the xml configuration file?? if that wrong plz tell me how can i do it

thanks
Feb 8 '08 #3
kunal pawar
297 100+
Write simple code

SqlConnection thisConnection = new SqlConnection(ur connection string);
thisConnection.open()
SqlCommand thisCommand = new SqlCommand()
thisCommand.connection = thisConnection
thisCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisReader["CustomerID"], thisReader["CompanyName"]);
}
thisReader.Close();
thisConnection.Close();
Feb 8 '08 #4
kunal pawar i still have problem T_T

An error has occurred while establishing a connection to the server. When conne
cting to SQL Server 2005, this failure may be caused by the fact that under the
default settings SQL Server does not allow remote connections. (provider: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Feb 8 '08 #5
gkn
4
It seems like the SQL server instance is not correct. Please check this first.
Feb 8 '08 #6
i created a database using sql sever 2005 using c# and i wanna connect to that database using this code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data.SqlClient;
  3.  
  4. namespace ConsoleCSharp
  5. {
  6. /// <summary>
  7. /// Summary description for Class1.
  8. /// </summary>
  9. class DataReader_SQL
  10. {
  11. /// <summary>
  12. /// The main entry point for the application.
  13. /// </summary>
  14. [STAThread]
  15. static void Main(string[] args)
  16. {
  17. //
  18. // TODO: Add code to start application here
  19. //
  20. try
  21. {
  22. SqlConnection thisConnection = new SqlConnection("Data Source=,1433;database=Database2;User id=;Password=;");
  23. SqlCommand thisCommand = thisConnection.CreateCommand();
  24. thisCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
  25. SqlDataReader thisReader = thisCommand.ExecuteReader();
  26. while (thisReader.Read())
  27. {
  28. Console.WriteLine("\t{0}\t{1}", thisReader["CustomerID"], thisReader["CompanyName"]);
  29. }
  30. thisReader.Close();
  31. thisConnection.Close();
  32.  
  33. }
  34. catch (SqlException e)
  35. {
  36. Console.WriteLine(e.Message);
  37. }
  38.  
  39. }
  40. }
  41. }
the problem is that when i create the database i get this connection string:

"Data Source=.\SQLEXPRESS;AttachDbFilename="D:\Documents and Settings\200302521\My Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplicati on1\Database1.mdf";Integrated Security=True;User Instance=True"

however in the code they used different connection string which is:

"Data Source=,1433;database=Database2;User id=;Password=;"

i wanna knew what is the different between these two string because i tried both
of them but i still get an errors.

thanks a lot;
Feb 9 '08 #7

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

Similar topics

0
by: AlessanBar | last post by:
Hello Friends !! I have a strange problem, and I need to know what would be the source of this. I have a laptop computer with the following configuration: Pentium III Brand : Toshiba Speed :...
2
by: Kevin R | last post by:
I'm trying to get asp.net 1.1 running on my home PC. When I try creating a new ASP.NET Web Application in 'Visual Studio .NET 2003' I get the following error: "Visual Studio .NET has detected...
17
by: Danieltbt05 | last post by:
just installed SQL server 2000 and using my client , i can't locate the server. I used SQL query analyzer to search but no servers were found. Error message is as below Server : Msg17,level...
1
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005...
16
by: Jeremy S. | last post by:
I'm about to install VS.NET 2005 and SQL Server 2005 on a new/clean development machine (XP Pro/SP2 etc). Is the order of installation important (i.e., which product should I install first)? ...
10
by: amjad | last post by:
how to connection sql server table with aspx like pulling data from table to grid view.... simple example to start .... thanks
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
3
by: Steve | last post by:
Hi All I downloaded Sql server 2005 express SP2 and attempted to modify the Bootstrapper package files as I did with SP1 When i try to install SQL server as part of my VS 2005 deployment app I...
3
by: Lee T. Hawkins | last post by:
I am having a number of problems over the last two full days trying to get an ASP.NET 2.0 application to connect to a SQL Server 2005 database... First off, I built this application w/ Visual...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
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,...
0
isladogs
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...

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.