Hi, I have problem with my connection to the database generate from entity data model of Ado.Net Entity framework. I work in Console Application. My code looks like that:

public static void Main(string[] args)
    {
        string connectionString = "Data Source=(localdb)\v11.0;Initial Catalog=BarDatabase;Integrated Security=True";

        using(SqlConnection con = new SqlConnection(connectionString))
    {
        string queryStatement = "SELECT TOP 5 * FROM dbo.Persons ORDER BY PersonId";
        using(SqlCommand cmd = new SqlCommand(queryStatement, con))
    {
        DataTable customerTable = new DataTable("Top5Customers");

            SqlDataAdapter dap = new SqlDataAdapter(cmd);

        con.Open();
        dap.Fill(customerTable);
        con.Close();

      } 
     } 

Throw me a statement: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

I copy the connection string from Properties of my local database. Where I do mistake?

Edited 4 Years Ago by kubiak

kubiak
Deleted Member

How have you created the DB...do you have SQL server installed...Make sure you are not trying to connect to SQL compact DB.

where is the name of your SQL-Server Name:
it schould look like this :

"Data Source=localdb\SQLEXPRESS;Initial Catalog=BarDatabase;Integrated Security=True";

while connecting to a sqlserver express and trying to run a stored proc a get this exception do someone have any idea??

how to upload files here???

Edited 4 Years Ago by grarhakim: how to upload files here???

how to upload files here???

In reply, click on Files then choose file

while connecting to a sqlserver express and trying to run a stored proc a get this exception do someone have any idea??

What exception are you getting?

that was an smoething like less parameter-exeception. but i have found the solution thanks for replying.

This article has been dead for over six months. Start a new discussion instead.