I'm just starting to get into some Service programming (WCF). I've successfully tried out the Microsoft WCF tutorial and got mathematical results from the service. Now I'm trying to set up a SQL Server Express database on the Service side so that it can allow the client to either retrieve data from the database or submit data via the service function calls and returns.

However, when I attempt to connect to the database on the service side, I get an error.

I selected Microsoft SQL Server Database File for the database type and Windows Authentication.

The connection string looks like this: "Data Source=.\\SQLEXPRESS; AttachDbFilename=(filepath);Integrated Security=True;Connect Timeout=30;User Instance=True"

When I Test the connection, I get this:

"An attempt to attach an auto-named database file for (filepath) failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."

I'm guessing this is because I'm attempting it with a SQL Server 2008 Express file rather than a SQL Server 2008 file (I had to select the All Files *.* filter in order to see my database file for selection). Is there any way to experiment with a WCF Service programmed in C# accessing a SQL Server 2008 Express file?

Thanks for any insight.

I've gotten a little closer, but still no luck.

I can successfully "Test Connect" in the Connect to Database screen using the SQL Compact Database selection, and it gives me a connection string of "Data Source=(filepath)". But using this in the actual code, even in a local non-service-using C# program, fails. It give me the 26 error and suggests I shoudl make sure SQL Server is set up for remote connection.

Why is it being so troublesome just to connect with a local file in a local app?

Again, any help would be appreciated.


In the C# project, I added a Service-based database and it created an .mdf database that I could connect with. I'm not sure what the .sdf file is, but I won't bother with that again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.