none
Can't create database from datacontext.

    Question

  • Hello, i uses this lesson http://msdn.microsoft.com/ru-ru/library/Bb399420(v=vs.110).aspx   try to create database, but on db.CreateDatabase() appear error 26.

    public class BD : DataContext
        {
            public BD(string cs)
                : base(cs)
            {
            }
            public Table<Equpment> Equpment
            {
                get
                {
                    return this.GetTable<Equpment>();
                }
            }
            public void Check()
            {
                if (!this.DatabaseExists())
                {
                    this.CreateDatabase();
                }
            }
        }
        [Table]
        public class Equpment
        {
            [Column(IsPrimaryKey=true)]
            public int id;
            [Column]
            public string name;
        }
    
    
    BD bd = new BD("D:\\113\\test.mdf");
                bd.CreateDatabase();

    Monday, April 14, 2014 2:06 PM

Answers

All replies

  • Hello Grey5,

    I do not know which scenario the sample is used so that when completely following the sample code throw an error: 26.

    I create the database with giving a connection string as:

    string connStr = String.Format(@"Data Source=(localdb)\Projects;AttachDbFilename={0};Integrated Security = SSPI;", @"d:\mydvds.mdf");

    This works fine for me. You can have a try. The whole demo is:

    using System;
    
    using System.Collections.Generic;
    
    using System.Data.Linq;
    
    using System.Data.Linq.Mapping;
    
    using System.Linq;
    
    using System.Text;
    
    namespace LINQToSQL
    
    {
    
        class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                string connStr = String.Format(@"Data Source=(localdb)\Projects;AttachDbFilename={0};Integrated Security = SSPI;", @"d:\mydvds.mdf");
    
               MyDVDs db = new MyDVDs(connStr);
    
                db.CreateDatabase();
    
                #endregion
    
            }
    
        }
    
        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;
    
        }
    
    }
    

    If this does not work for you, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 15, 2014 5:04 AM
  • Not working. I am getting error 50. But i am find that with coonnection string like this 

    @"Data Source=(LocalDB)\Projects;AttachDbFilename=d:\mydvds.mdf;Integrated Security = SSPI;"

    Data base working. Thanks.

    Tuesday, April 15, 2014 4:15 PM