connecting to sql server 2000 from c#2008

connecting to sql server 2000 from c#2008

Page 1 of 1

1 Replies - 6109 Views - Last Post: 29 June 2008 - 03:58 PM Rate Topic: -----

#1 nsncreations  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-June 08

connecting to sql server 2000 from c#2008

Posted 29 June 2008 - 11:18 AM

connecting to sql server 2000 from c#2008


dear friends,

i have sqlserver2000 installed in my desktop and vs 2008 in my laptop, now i am trying to connect local sqlserver2005 express on laptop i am able to connect, but if i am trying to connect to sqlserver2000 on my desktop i am not able to connect to my database.

hear is the sample code:-


using System;
using System.Data;
using System.Data.SqlClient;
namespace Chapter09
{
    class SqlServerProvider
    {
        static void Main(string[] args)
{
// set up connection string
string connString = @"server = NSN\NSN;integrated security = true;database = northwind";

   // string connString = @"server =nsn;integrated security = true;database = northwind";

            // set up query string
string sql = @"select * from employees ";
// declare connection and data reader variables
SqlConnection conn = null;
SqlDataReader reader = null;
try
{
// open connection
conn = new SqlConnection(connString);
conn.Open();
// execute the query
SqlCommand cmd = new SqlCommand(sql, conn);
reader = cmd.ExecuteReader();

// display output header
Console.WriteLine( "This program demonstrates the use of " + "the SQL Server Data Provider." );
Console.WriteLine( "Querying database {0} with query {1}\n" , conn.Database , cmd.CommandText );
Console.WriteLine("First Name\tLast Name\n");
// process the result set
Console.WriteLine("|___________|___________|");
while (reader.Read())
{
    Console.WriteLine("|{0} | {1}|", reader["FirstName"].ToString().PadLeft(10), reader[1].ToString().PadLeft(10));
    Console.WriteLine("|___________|___________|");

}
}
catch (Exception e)
{
    Console.WriteLine("error" + e);
Console.WriteLine("Databse Not Found..." );
}
finally
{
// close connection
    Console.WriteLine("closing reder and connections");
    Console.ReadLine();
reader.Close();
conn.Close();
}
}
    }
}



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: connecting to sql server 2000 from c#2008

#2 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 282
  • View blog
  • Posts: 1,489
  • Joined: 07-April 08

Re: connecting to sql server 2000 from c#2008

Posted 29 June 2008 - 03:58 PM

some things to make sure of.

You need both remote connections and named pipes enabled on your SQL server. Make sure your computer is accepting incoming connections also. then i would suggest when you set up the server to assign it a port number and use the ip:port method of connecting


I.E:

if my computers ip was 192.168.1.110 and i assigned the port number of 1177 the connection would look like so:

# string connString = @"server =192.168.1.110,1177;integrated security = true;database = northwind";  


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1