I know that this is well-covered ground, but for some reason I have been unable to get this database connection working. This is my first project using .net systems instead of PHP/MySQL so I'm not quite sure how things are working. I've spent the morning trying different connection strings and running through tutorials and I'm finally posting here in the hope that someone can kick me in the right direction : )
The connection code I have is:

SqlConnection myConnection = null;
            try
            {
                myConnection = new SqlConnection(@"Data Source=C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Samples\Northwind.sdf;Persist Security Info=True");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error during database connection: "+e.ToString());
            }

            try
            {
                myConnection.Open();


            }
            catch (Exception e)
            {
                Console.WriteLine("Error opening database connection: "+e.ToString());


            }

This always fails at .open();

What is the error message you are getting? You should evaluate e.Message inside of your catch() statement

The error reads:

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Ok, I solved this by connecting to an instance of SQL Server rather than SQL Compact 3.5

This question has already been answered. Start a new discussion instead.