0

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 by kubiak

4
Contributors
7
Replies
13
Views
4 Years
Discussion Span
Last Post by grarhakim
0

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

0

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

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

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 by grarhakim: how to upload files here???

0

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?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.