-3

I have problems with connecting to my local database. Type of database is .sdf (SQL Server Compact Edition). And I don't understand what is wrong. When I look in my server explorer in data connections at first is ok after running the project it shows on my database bottom red cross.

When I run project I get error:

SqlException was unhandled - A network-related or instance-specific error occurred while establishing a connection 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 app.config file contains:

<connectionStrings>
    <add name="Project3.Properties.Settings.Database1ConnectionString"
         connectionString="Data Source=:C\Users\visualstudio\Project3\Database1.sdf"
         providerName="Microsoft.SqlServerCe.Client.3.5" />
 </connectionStrings>

And I have also in Program.cs:

 string connectionString = Properties.Settings.Default.Database1ConnectionString;

 using (SqlCeConnection conect = new SqlCeConnection(connectionString))
 {
      conect.Open();
 }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

6

Is your datasource correct

Data Source=:C\Users\visualstudio\Project3\Database1.sdf

should it not be

Data Source=C:\Users\visualstudio\Project3\Database1.sdf
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
codingpirate
  • 1,414
  • 1
  • 12
  • 20