Sqlconnection failure in C#

Asked

Viewed 408 times

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 in a form to mecher offline and speaks at the beginning

Warning 1 The field 'Windowsformsapplication1.Form3.dataRead' is Never used C:... Windowsformsapplication1 Form3.Cs 23 23 Windowsformsapplication1

and at the time to press save of this error.

Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: Named Pipe Provider, error: 40 - Unable to open 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

  • Didn’t have to have the base path inside the string Connection?

1 answer

0


This is not a mistake. It’s a warning (Warning):

Warning 1 The field 'Windowsformsapplication1.Form3.dataRead' is Never used C:... Windowsformsapplication1 Form3.Cs 23 23 Windowsformsapplication1

Are you just saying that you are not using the informed component anywhere in your code.

About the connection, the Connection string is wrong. If you want to point to Connection string for an SDF file, the correct 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;

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

  • Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: SQL Network Interfaces, error: 26 - Server Locate Error/Specified Instance)

  • when I give ABC.Open();

  • I put a note for you. The classes have a slightly different name because they are SQL Server Compact.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.