Hi all,
i am trying some code examples given in a book. I am getting an error while connecting to the database.I have installed sqlexpress edition and trying to connect to system database "master".
Below is the error message:
"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)"
And here is the code which i am trying.
class Program
{
static void Main(string[] args)
{
// Create a connection string builder
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
// Define connection string attributes using three techniques
csb.DataSource = "(local)";
csb.Add("Initial Catalog", "master");
csb["Integrated Security"] = true;
// Output the connection string from the connection string builder
Console.WriteLine("Connection string:\n{0}", csb.ConnectionString);
// Create a connection string from the connection string builder
SqlConnection connection = new SqlConnection(csb.ConnectionString);
// Open and close the connection
connection.Open();
Console.WriteLine("\nConnectionState = {0}", connection.State);
connection.Close();
Console.WriteLine("ConnectionState = {0}", connection.State);
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
}
}
pls help me...
Thanks