Connection using oledb
I have to connect sql database with c#.net using oledb!!If anybody could suggest?????Please help!!!!!!
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Feb 20, 2010, 11:12 PM EST
you can connect to SQL Server like Below
using System.Data.SqlClient;
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
Anshul Shukla14 reputationPosted Feb 20, 2010, 11:18 PM EST
Kirtan PatelRank #292 · 8.6K reputationPosted Feb 20, 2010, 11:30 PM EST
if you move your project to another machine ..just you should take care that database file should be in same folder where exe of application is there ..
as |DataDirectory| word Will Look in to root folder where exe is there so its not matter of fixed path :)
Thats it ..and if still you need customization then you can use Application Settings to Store Connection String As I mentioned as one Of Question you asked on this forums.. :)
Happy Coding :)
Anshul Shukla14 reputationPosted Feb 20, 2010, 11:34 PM EST
I'll be trying this and let u know!!!
Kirtan PatelRank #292 · 8.6K reputationPosted Feb 20, 2010, 11:43 PM EST
ask me whatever problem you are facing .while connecting to Database :)