none
DataContext.CreateDatabase() doesn't work! RRS feed

  • Question

  • Hello, this is my test code:

    public class MyDVDs : DataContext
    {
     public Table<DVD> DVDs;
     public MyDVDs(string connection) : base(connection) { }
    }
    [Table(Name="DVDTable")]
    public class DVD
    {
     [Column(IsPrimaryKey=true)]
     public string Title;
     [Column]
     public string Rating;
    }
    
    
    static void Listing()
    {
     MyDVDs db = new MyDVDs("c:\\123\\mydvds.mdf");
     db.CreateDatabase();
    }
    I get stable error on it run:
    System.Data.SqlClient.SqlException was unhandled
      Message="A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

    And so I have a couple of questions. First is self-evidence - what's wrong with code? Second is may be more interesting - WHERE LINQ is going to connect to? I just don't provide any connection string! So where is that SQL Server LINQ try establishing a connection to?
    Sunday, May 31, 2009 5:57 PM

All replies

  • Provided you have completed other parts it would look like:

    MyDVDs

     

    db = new MyDVDs(
       @"Server=.\SQLExpress;AttachDbFilename=c:\123\myDVDs.mdf;Database=myDVDs; Trusted_Connection=yes");
    db.CreateDatabase();

    I would do it in SQL first (development) and generate the dbml with designer (or SqlMetal).

    Monday, June 1, 2009 11:53 AM
  • What if I just don't want any SQL Servers? I only want .mdf file with DVDTable. It will NOT "full value" DB on big SQL Server, just a file. Or, even simpler - I don't have SQL Server and don't want install it. And so? I can't create .mdf file in this case??

    Monday, June 1, 2009 12:21 PM
  • What if I just don't want any SQL Servers? I only want .mdf file with DVDTable. It will NOT "full value" DB on big SQL Server, just a file. Or, even simpler - I don't have SQL Server and don't want install it. And so? I can't create .mdf file in this case??


    No you can as you could create any filename you want on a filesystem but that wouldn't be an SQL server database file and I don't know what would you use it for then. Maybe you should check SQL server CE which is light or some other backend like VFP, XML which do not require specific services (VFP needs VFPOLEDB).
    Monday, June 1, 2009 3:49 PM