简体   繁体   中英

How to fix: “Database Cant be imported” in C# using Visual Studio

I'm making a program for a C# project using Visual studio, and whenever I tried to insert the data into the database, it succeeded. But whenever I tried to refresh the db, it gives "The Database cannot be Imported. It's either an Unsupported SQL Server Version or an unsupported database compatibility" error.

The form i used is Windows Forms App (.NET Framework) and the database is SQL Server Database Project

Tried changing the Copy to Output directory to copy if newer, didn't work.

The code to save the input in registration form

using (DatabaseProjectEntities db = new DatabaseProjectEntities())
{
    db.MsUser.Add(usertemp);// msuser is name of the table &                          
                            // usertemp type is MsUser
    db.SaveChanges(); // saves

    MessageBox.Show("Success!");
    this.Close(); // form closes
}

After I used the registration form, it shows MessageBox "Success!".

It saves into the current running program, but when I tried to refresh the database, it shows the error.

But when I tried to login in login form


using (DatabaseProjectEntities db = new DatabaseProjectEntities())
{

    var peperesult = (...
        // selecting required data
        }
    );
...
//if else statement checking data is available in the database or not
    else
    {
        MessageBox.Show("Login Success");
        this.Close();
    }

It shows "Login success", meaning the data already inserted.

If I close the running program, the data doesn't get inserted.

Update #1, I managed to make it work by simply use the database in bin/debug, however, since i have to submit it to other person, i have to use the database inside the project instead of using the visual studio one.

Apparently, When my colleague made the first part of the project, he used an outdated Visual Studio to make it. Creating an older version of the Database.

After using the same version of Visual Studio. Change the Database behavior to Copy If Newer. It doesn't have any problem at all.

Guess next time I'm going to make sure we are all using the same version. :/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM