I am trying to learn ADO.NET to connect with SQL Server …
I install SQL Server with Visual Studio ….
there is data base called “Northwind” as example with it …
I am trying to read this database , I wrote this code …
using System;
using System.Data;
using System.Data.SqlClient;
namespace DataSetReaderFromSQL
{
class Program
{
static void Main(string[] args)
{
SqlConnection connection = new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;" + "Initial Catalog=Northwind");
connection.Open();
SqlCommand command = connection.CreateCommand();
command.CommandText = "Select CustomerID , CompanyName from Customers";
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine(reader["CustomerID"] +""+ reader["CompanyName"]);
reader.Close();
connection.Close();
}
}
}
When the application runs, it’s take a little of time then throw exception when it trys to open connection …
the text of the exception :
A network-related or instance-specific
error occurred while establishing a
connection to SQL Server. The server
was not found or was not accessible.
Verify that the instance name is
correct and that SQL Server is
configured to allow remote
connections. (provider: Named Pipes
Provider, error: 40 – Could not open a
connection to SQL Server)
I am using Windows 7 as my operating system, and I put username on my account …
I am sure that SQL Server was installed on my computer
where is my error ??
Either
.\SqlExpressor just.Ordinarily when Visual Studio installs Sql Server Express, it installs it as a named instance called SqlExpress.