Alex
Alex

Reputation: 681

Creating and utilizing a local database in Visual Studio 2010

I can't seem to find any straight-forward guides on how to create a windows forms application with C# .NET in Visual Studio 2010 that uses a local database. When I create the local database, a .sdf file, I can't figure out how to have my form access it. All the discussions I have been able to find on it seem to assume I know more than I do on the subject. Can anyone direct me towards a straight-forward beginner's guide on the subject, or outline the steps I need to take?

Upvotes: 4

Views: 22731

Answers (2)

Lord Darth Vader
Lord Darth Vader

Reputation: 2005

I found this library very helpful

https://github.com/martincostello/sqllocaldb

Once added via nuget its very easy to use

ISqlLocalDbProvider provider = new SqlLocalDbProvider();
ISqlLocalDbInstance instance = provider.GetOrCreateInstance("MyInstance");

instance.Start();

using (SqlConnection connection = instance.CreateConnection())
{
    connection.Open();

    // Use the connection...
}

instance.Stop();

Upvotes: 0

Stephen Byrne
Stephen Byrne

Reputation: 7505

Check here, it will walk you through what you need to do...if you have any specific issues with specific parts of the linked process, let us know.

Upvotes: 3

Related Questions