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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Feb 21, 2010, 4:12 AM
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();
Kirtan PatelPosted Feb 21, 2010, 4:43 AM
ask me whatever problem you are facing .while connecting to Database :)
Anshul ShuklaPosted Feb 21, 2010, 4:34 AM
I'll be trying this and let u know!!!
Kirtan PatelPosted Feb 21, 2010, 4:30 AM
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 ShuklaPosted Feb 21, 2010, 4:18 AM