Member Avatar for kubiak

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?

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";

localdb is the name of your machine

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???

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.