Hi guys I've been trying to connect my c# file to my database file(in .mdf format created in SQL Server Management Studio 2008). So basically I used visual studio 2008 for my C# file and SQL Server Management Studio 2008 for my database file. Now I'm sure that the naming conventions that I used in C# are the same as the naming conventions with my .mdf database file.

Now I tried to follow the instructions written in this link: http://www.homeandlearn.co.uk/csharp/csharp_s12p1.html

Unfortunately I wasn't able to make it run properly, I mean whenever I type data in my c# app it doesn't appear on the tables that I executed in my .mdf file in management studio... I will upload the files both the C# app and the database file so you can test it, and I hope the link that I have included in this post will be a bit helpful. Please inform me guys how you did it if ever you were able to connect and run them properly. All helps will be very appreciated. Thanks in advance!

You only need the correct connection string to access to database.
And if SSMS (with database) is located on different pc, then you have to open a 1433 port (potr that is used to access to sql server by defalut) in the firewall.

for those who cannot download the c# app here it is:

hey mitja_bonca try to download the zip file I just uploaded, link is working bro.

Try taking out the AttachDbFilename part, so it would go from:

con.ConnectionString ="DataSource=.\SQLEXPRESS; AttachDbFilename =C:\MyWorkers.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

to something like this:

con.ConnectionString ="DataSource=.\SQLEXPRESS; Integrated Security=True;Connect Timeout=30;User Instance=True";

The database file is already attached to the instance of SQLEXPRESS. This may be causing some undesireable results.

I'm not going to download and look through all of your code. If you post some code (ie. where you created the SqlConnection class, and how you're using it) I'll take a look, but atleast try my above suggestion first.

@Lightning03 do not double post same question twice. Either close this or the other post and mention that discussion continue in different thread leaving link at the end

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.