首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

关于CreateDatabase。解决方案

2012-12-23 
关于CreateDatabase。。。public class NewCreateDB : DataContext{public TablePerson Personspublic New

关于CreateDatabase。。。
关于CreateDatabase。解决方案
public class NewCreateDB : DataContext
{
    public Table<Person> Persons;     
       public NewCreateDB(string connection) : base(connection)     
       {     }     
       public NewCreateDB(System.Data.IDbConnection connection) : base(connection)    
       {     }     
}     
[Table(Name = "Person")]     
public partial class Person : INotifyPropertyChanged     
{     
    private int _PersonID;     
    private string _PersonName;    
    private System.Nullable<int> _Age;     
    public Person() 
    { }     
    [Column(Storage = "_PersonID", DbType = "INT", IsPrimaryKey = true)]     
    public int PersonID     
    {     
        get 
        { return this._PersonID; }     
        set     
        {     
            if ((this._PersonID != value))     
            {     
                this.OnPropertyChanged("PersonID");     
                this._PersonID = value;      
                this.OnPropertyChanged("PersonID");    
                               
            }    
                          
        }    
                    
    }     
    [Column(Storage = "_PersonName", DbType = "NVarChar(30)")]     
    public string PersonName     
    {     
        get 
        { return this._PersonName; }     


        set     
        {     
            if ((this._PersonName != value))             
            {     
                this.OnPropertyChanged("PersonName");                
                this._PersonName = value;                 
                this.OnPropertyChanged("PersonName");                 
            }              
        }                   
    }     
    [Column(Storage = "_Age", DbType = "INT")]     
    public System.Nullable<int> Age     
    {     
        get 
        { return this._Age; }         
        set     
        {     
            if ((this._Age != value))               
            {     
                this.OnPropertyChanged("Age");                 
                this._Age = value;                   
                this.OnPropertyChanged("Age");               
            }                 
        }                      
    }     
    public event PropertyChangedEventHandler PropertyChanged;     
    protected virtual void OnPropertyChanged(string PropertyName)     
    {     
        if ((this.PropertyChanged != null))     


        {     
            this.PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));    
        }    
    }    
}
************************************************
static void Main(string[] args)
        {
            //新建一个临时文件夹来存放新建的数据库  
            string userTempFolder = Environment.GetEnvironmentVariable("SystemDrive") + @"\YJingLee";   
            Directory.CreateDirectory(userTempFolder);   
            //新建数据库NewCreateDB  
            string userMDF = System.IO.Path.Combine(userTempFolder,  @"NewCreateDB.mdf");  
            string connStr = String.Format(@"Data Source=.\SQLEXPRESS;  
                                             AttachDbFilename={0};Integrated Security=True;  
                                             Connect Timeout=30;   Integrated Security = SSPI;", userMDF);  
            NewCreateDB newDB = new NewCreateDB(connStr);  
            newDB.CreateDatabase();               //插入数据并查询  
            var newnewRow = new Person  
            {  
                PersonID = 1,  
                PersonName = "YJingLee",  
                Age = 22 
            }; 
 

        }
求大神解答,正确的代码我不能用啊。。。
[解决办法]
其实该问题解决非常简单,只需 
1右键点击数据库所在的文件夹, 
2点击属性,在常规选项卡中点击高级, 
3在弹出的窗口中的压缩或加密属性中去掉压缩内容或者节省磁盘空间,点击确定 
4点击应用,勾选应用于该文件夹所有文件 即可

------
原因:

NTFS 或 FAT 压缩卷上不支持 SQL Server 数据库。 压缩卷无法保证扇区对齐方式的写入,但这种写入在某些情况下是确保事务恢复所必需的。 此外,建议不要将 SQL Server 数据库备份为压缩卷上的磁盘文件。 

热点排行