I created my data model using Entity Framework, when I try to generate the database from the model, it generates the script but when I execute it I have the following error:
Msg 911, Level 16, State 1, Line 1
Database 'MyOp' does not exist. Make sure that the name is entered correctly.
I don't know where is the error, I don't think that is a problem of permissions.
Thank you for your help
Ok I found it, sorry to ask such a question.
The problem was that my database was not created in my server, so I created it that way:
In SQL connecxion in visual studio, right click and add new database,
in the dialog box of the server name type ".\SQLEXPRESS" (without quotes).
Type the name of your db in the database name.
Now when executing your script, choose your database name instead of "master" in the dropdown list next the the excexution button.
WARNING: when changing laptop I did'nt find my created database, so you have to copy/paste it in the appdata folder in your application, to copy your database, you will find it in this path: C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA
you must click disconnect button and then connect button .vs2012 select sqlExpress by defult when you want connect again to your server you must select server name correctly.
Related
I added a field to this table: STG_INVOICE_SUP_VW
But then I wasn't able to synchronize the table so I deleted it. Now if I'm trying to synchronize any table it's throwing this error below:
Cannot execute a data definition language command on (). The SQL
database has issued an error.
SQL error description: [Microsoft][SQL Server Native Client 11.0][SQL
Server]Cannot drop the index
'STG_INVOICE_SUP_VW._dta_index_STG_INVOICE_SUP_VW_25_692157136__K7_1_2_3_4_5_6_8_9_10_11_12_13_14_15_16_17_1',
because it does not exist or you do not have permission.
SQL statement: DROP INDEX
STG_INVOICE_SUP_VW._dta_index_STG_INVOICE_SUP_VW_25_692157136__K7_1_2_3_4_5_6_8_9_10_11_12_13_14_15_16_17_1
Problems during SQL data dictionary synchronization. The operation
failed.
Synchronize failed on 1 table(s)
Edit:
Entire issue was related to an additional index created from SQL side.
If you create an Index on AX tables from SQL side then either you won't be able to synchronize the table or your created index will be dropped on synchronization(as suggested by by some users).You should create indexes from Application Object Tree.
I Deleted the index from SSMS and then synchronize worked perfectly.
It also solved one more issue. Incremental CIL was throwing an error below:
Cannot create a record in SysXppAssembly (SysXppAssembly). The record
already exists.
For incremental CIL issue I had already done the steps pointed here but it didn't fix it:
Stop the AOS Navigate to the XppIL folder in your AOS server
“C:\Program Files\Microsoft Dynamics
AX\60\Server\YourAXInstanceName\bin\XppIL”
Backup the files from the XppIL folder.
Delete the files from the XppIL folder. Note: files
only not sub folders.
Restart the AOS.
The XppIL folder files will be created after the AOS restart
From this link: Community.Dynamics
After fixing the table sync issue, Incremental CIL ran without issue.
Try creating index STG_INVOICE_SUP_VW._dta_index_STG_INVOICE_SUP_VW_25_692157136__K7_1_2_3_4_5_6_8_9_10_11_12_13_14_15_16_17_1 directly in SQL Server and then re-run DB sync in AX.
I've got ASP.NET MVC App with database added as Code First from Database. Now I need to create new table in datebase and add column in other. I've create it manually on database, now my question is how can I update database in Visual Studio project to show and allow me to use my created table? I've tried deleted all classes and connection string and add database again, but I've got exception:
"This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection."
Also helpfull will be information/link to tutorial how can I add a table from Visual Studio and sent changes to database.
Thanks for any help.
I am following this tutorial (http://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database) in order to create a database-first app with Entity Framework.
I hit "Run" and everything seems to be working, but in the next part of the tutorial (https://www.asp.net/mvc/overview/getting-started/database-first-development/creating-the-web-application), when I try to add a connection, it's not in the drop-down menu in the "Connection Properties" box under "Select or enter a database name".
Which server is the database on? I didn't specify anything about the server when I created the project for the first tutorial, and I figured that it would be on the default LocalDB that comes with Visual Studio (server name: (localdb)\MSSQLLocalDB), but the database isn't there. Any ideas where I should look or what to try?
Maybe use . (a dot) as Server Name?
Open your Web.config file and check your <connectionStrings> this is where the data source of the database will be. As shown:
However, which version of SQL Server do you have? As this can determine what the correct connection string will be.
Hit Windows+R. And run the following:
%LOCALAPPDATA%\Microsoft\Microsoft SQL Server Local DB\Instances
You may have multiple instances, it would be worth checking each one. So it would be:
(localdb)(name of instance)
This article may also be of use to you:
http://rajchel.pl/2015/10/solving-connection-issue-with-sql-server-2014-localdb/
What could be the case is that you have to run the application you created, and then do something to touch the database like creating / registering a user. After registration you can find the database on the specified location in your web.config settings. This was the solution in my case.
I created website using asp.net MVC with Entity Framework Code First. It worked before on Windows Azure, the site was available publicly.
For some reason, I deleted database that was used to store data of my webpage. I created new one, similar to previous one.
I properly connected my site to database (in solution I clicked "Publish", in "Settings" there is place to type data about database, in "Destination Connection String" window I typed all needed data and clicked "Test Connection" - everything seems to be fine)
I published my site, the site works correctly, but when I go to page that gets data from database is see this error:
Invalid object name 'dbo.AspNetUsers'.
In Visual Studio in "SQL Server Explorer" I can see what is in my database. In fact, there is nothing inside (there is one table: "__MigrationHistory" and as I suspect this is created by default).
How can I generate all those tables again? It should generate database structure automatically.
PS: Accidentally I deleted "migations" from my project, do you think this is the cause?
This is not my projects blame, it works OK on localhost on my computer, when I delete localDB, it generates new one without any problem.
Yes, you need migrations. But you can always re-create them (well, if you removed them all it will be initial migration containing all of your previous migrations).
To quick fix you can backup and restore you database on the server. And if you need to re-create migrations do the following:
Backup all your data
Delete the entire database (local and remote), delete all migrations from code.
Create databases (local and remote one).
Run "add-migration Initial" command from PM console
Run "update-database" from PM console.
Upload your code to the server again. If database is empty, new initial migration should be automatically applied.
I am on VS 2012 RTM, with EF 5. I am doing Code First, but trying to ignore Code Migrations since I am just in development. To avoid them, I have this set
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<SomeContext>());
Occasionally, even when I don't think I've touched the model, it decides to recreate. That's fine. But it usually results in the error
Cannot drop database because it is currently in use.
So I decided to delete the database entirely. I go into VS, go to the "SQL Server Object Explorer", find the DB and delete it. Now I'm stuck at
Cannot attach the file '{0}' as database '{1}'
I had this happen last night and I just fiddled around until it work (shut down tasks, restart VS, changed the DB and file names in the web.config, etc.
So question 1) How do I get out of this state?
But the more important question, how do I prevent myself from getting in this state at all?
The SQL Server Object Explorer window can hold a connection to the database. Closing the window and all windows opened from it releases the connection.
I had the same problem and managed to fix it. The main problem is that EF won't automatically create the database. The solution is not very hard.
First, go to the Solution Explorer and manually create the database. To do this, go to the folder where your database is located (usually App_Data). Right-click on this folder and click on Add -> New Item. Select the Data tab and select SQL Server Database. Make sure you enter the name Entity Framework expects (which is specified in the Cannot attach the file '{0}' as database '{1}' error message).
Then most likely you will get an error message that says that the database does not contain any model metadata. To circumvent this, change your database initialisation to:
Database.SetInitializer(new DropCreateDatabaseAlways<SomeContext>());
Now run the application and the database should be there with tables correctly created. Once this step has been successfully executed, you change change your database initializer back to:
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<SomeContext>());