none
Database connection error RRS feed

  • Question

  • Hello,

    i begin with linq and i have a problem to connect to the database, for the datacontext, i use the one generated by sqlmetal.

    I use the following code
    Test db = new test(@"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\test.mdf");
    Table<Context> context = db.GetTable<Context>();
                var ContextList = (from e in context select e).ToList();


    And the error is:

    Files\Microsoft SQL Server\MSSQL.1\MSSQL\test.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.


    Monday, September 8, 2008 8:20 AM

Answers

  • The exception message seejs very generic, Can you try out the following:

    • Check ACLS on the file directory to verify you have permissions.
    • Is the database accessible directly, while not using LinqToSQL
    • Try out following connection syntax for SQLExpress

    Test db = new test("Data Source=.\\SQLEXPRESS;AttachDbFilename=\"" + @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\test.mdf" + "\";Integrated Security=True;Connect Timeout=30");

     

    ~Deepti

     

     

     

    Wednesday, September 10, 2008 5:23 PM
  • It's probably locked. Close Management Studio and try again.

     

    A.D.T.

     

    Wednesday, September 10, 2008 5:25 PM
  • Are you running this in Vista?  Your application may some issues when you access files in Program Files directory.  Try moving your database into a different directory outside of Program Files.

     

    Friday, September 12, 2008 9:48 PM

All replies

  • The exception message seejs very generic, Can you try out the following:

    • Check ACLS on the file directory to verify you have permissions.
    • Is the database accessible directly, while not using LinqToSQL
    • Try out following connection syntax for SQLExpress

    Test db = new test("Data Source=.\\SQLEXPRESS;AttachDbFilename=\"" + @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\test.mdf" + "\";Integrated Security=True;Connect Timeout=30");

     

    ~Deepti

     

     

     

    Wednesday, September 10, 2008 5:23 PM
  • It's probably locked. Close Management Studio and try again.

     

    A.D.T.

     

    Wednesday, September 10, 2008 5:25 PM
  • Are you running this in Vista?  Your application may some issues when you access files in Program Files directory.  Try moving your database into a different directory outside of Program Files.

     

    Friday, September 12, 2008 9:48 PM