4 Replies - 3570 Views - Last Post: 28 August 2012 - 12:43 AM Rate Topic: -----

#1 loqman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-August 12

how to attach a database to a C# program

Posted 26 August 2012 - 10:26 AM

hello
I have a local database (.mdf) and I want to attach this database to my C# windows application.
how I can attach this database and how I can connect to it.
also I have (.xml) and (.sql) and (.accdb) file of my database which one is better.
I should add that the database is static and I just want to read it and I dont want to write on it.

thanks

This post has been edited by tlhIn`toq: 26 August 2012 - 10:35 AM
Reason for edit:: This is neither a church nor mosque website. Keep the deities and preaching where it belongs.

Is This A Good Question/Topic? 0
  • +

Replies To: how to attach a database to a C# program

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: how to attach a database to a C# program

Posted 26 August 2012 - 10:34 AM

See FAQ # 26. (Click the SHOW button below)



TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated July 2012
Spoiler



This post has been edited by tlhIn`toq: 26 August 2012 - 10:34 AM

Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,158
  • Joined: 05-May 12

Re: how to attach a database to a C# program

Posted 26 August 2012 - 12:35 PM

What do you mean by "I want to attach this database to my C# windows application"?

The question is usually phrased as "I want my C# windows application to connect to/attach to a database". This mean that you want to open an existing database.

My understanding of your statement is that you want to be able to deploy your application with the database, either as a file that lives alongside with the application, or as an embedded resource.
Was This Post Helpful? 0
  • +
  • -

#4 loqman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-August 12

Re: how to attach a database to a C# program

Posted 27 August 2012 - 06:47 PM

OK .you are right and your understanding is true.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,158
  • Joined: 05-May 12

Re: how to attach a database to a C# program

Posted 28 August 2012 - 12:43 AM

In the bad old days before Vista, you simply had your setup program place your .mdf in the same directory as your program. When Vista came around and there were permissions issues with writing into the Program Files directory, then the correct long term answer is to place your .mdf in the current user's LocalApplicationData directory. http://msdn.microsof...cialfolder.aspx

If you absolutely know that the database engine that you are using WILL NOT EVER write to the data file if you only ever do reads, then I think you can get by with having your data file in the same folder as your program. I've not verified it, but I've been told that the various flavors of the SQL database engines and the Jet database engine will write to the file anyway even if the only thing you ever do is query.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1