SqlConnection failed in C #

3
      SqlConnection ABC = new SqlConnection(
        "Data Source=(local);Initial Catalog=Database1;Integrated Security=SSPI");
    SqlCommand command = new SqlCommand();
    SqlDataReader dataRead;

I'm using this code to make a save button on a form to go offline and speak at the beginning

  

Warning 1 The field 'WindowsFormsApplication1.Form3.dataRead' is never used C: ... WindowsFormsApplication1 \ Form3.cs 23 23 WindowsFormsApplication1

and at the time of pressing the save of this error.

  

Network-specific or instance-specific error when connecting 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)

My base date is

  

Data Source = C: \ Users \ Somline \ Documents \ Visual Studio 2008 \ Projects \ PROGRAM \ WindowsFormsApplication1 \ Database1.sdf; Persist Security Info = True

    
asked by anonymous 27.04.2016 / 16:49

1 answer

0

This is not an error. This is a warning:

  

Warning 1 The field 'WindowsFormsApplication1.Form3.dataRead' is never used C: ... WindowsFormsApplication1 \ Form3.cs 23 23 WindowsFormsApplication1

You're just saying that you're not using the informed component anywhere in your code.

On the connection, the connection string is wrong. If you want to point the connection string to an SDF file, the correct one is:

SqlCeConnection ABC = new SqlConnection(
    "Data Source=C:\Users\Somline\Documents\Visual Studio 2008\Projects\PROGRAMA\WindowsFormsApplication1\Database1.sdf;Persist Security Info=False");
SqlCeCommand command = new SqlCommand();
SqlCeDataReader dataRead;

Notice that the classes are SQL Server Compact, not normal SQL Server ( SqlCeConnection , SqlCeCommand , SqlCeDataReader ). It has Ce in the middle of the name.

    
27.04.2016 / 17:27