0

I'm trying to write a Windows Form app. I need to use a database and since I know how to create a db in WP8 (using Datacontext) I tried to use the same class with this form project. I have a problem: how can I define the connectionstring in the StudentDatacontext class in order to create a local database in the folder of my application?

(I aleready tried using

public static string ConnectionString = @"c:\students.mdf";

but my application explodes on db.CreateDatabase();

    using (StudenteDataContext db = new StudenteDataContext(StudenteDataContext.ConnectionString))
            {
                if (!db.DatabaseExists())
                {
                    db.CreateDatabase();
                }

)

Thank you for the help!

DJ Burb
  • 2,346
  • 2
  • 29
  • 38
giofx
  • 1
  • 1
  • 1
    Can you post the stack trace? – Eisenhorn Nov 18 '14 at 15:41
  • yeah. we need to see the exact error – DJ Burb Nov 18 '14 at 15:41
  • possible duplicate of [Connection String to Connect to .MDF](http://stackoverflow.com/questions/928813/connection-string-to-connect-to-mdf) – Kami Nov 18 '14 at 15:42
  • @eisenhom can you please tell me if the syntax of the connectionstring is correct? – giofx Nov 18 '14 at 15:52
  • You can check that out yourself at connectionstrings.com Also this might be a relevant read for you: https://stackoverflow.com/questions/173209/how-do-i-connect-to-an-mdf-microsoft-sql-server-database-file-in-a-simple-web – Eisenhorn Nov 18 '14 at 15:54
  • Ok, I may have undeerstood my mistake and I need someone to please explain me if I'm right: on WP8 I used to create a local database, a file, in the internal memory, and datacontext used to do the remaining work. Now on Windows form application do I have to connect to a sql server (or something like that) in order to use a database (a local database, stored in myprojec folder) ? Or I can behave like Iused in WP8 ? – giofx Nov 18 '14 at 20:13

0 Answers0