VS22 Database project object with same name in different databases - database

I have a database project in VS2022 that contains several databases, each as their own project.
I repeatedly have problems with objects in different databases, that have the same name. E.g. in Db1 there is a user called "job". Db2 also has a user called "job" and uses data from Db1. Now, when I try to build Db2 I get an error model already has an element that has the same name.
This happens with users, tables, procedures, ... but somewhat randomly. Some tables in different databases have the same name and while building no error occurs. Then sometimes if I change anything in the Database model suddenly such errors happen although it worked for months before. I recently changed the collation of a database and suddenly I get dozens of this "already has an object" although the same databases worked before. Sometimes it can be fixed by closing VS22, removing the .dbmdl files and reopen the project, sometimes not.
I could change all objects to include their unique database name, but this would be a lot of work and not reasonable since tables with the same name in different databases shouldn't be a problem. Does anyone know why those errors occure randomly and how could one avoid that?

Related

My MSSQL production database suddently recreated all tables in new schema with NO data :-(

In our system, we suddenly lost all data. Noone could log into the system and the data was suddenly empty.
A closer look into the database showed, that there is now double the tables that there was before, just with another schema name in front of it instead of the standard DBO, it is not Timenord.tablename. All the data is still in the DBO tables, but the system is trying to use the new tables.
We havent been making any update to the system for a couple of days, so why this sudden behavior?
How do I fix it? Im using .net core 2.2, and i have never seen this issue before.
Dont even know how to tell the system to use the other schema.....
From comments above, temporary fix at least till you can find the cause of the issue is to set default schema:
How to set the default schema of a database in SQL Server 2005?
The default schema should look at a specific schema first (if you dont specify in your code like this dbo.TableName) so it will look for dbo. and if it finds the object should use that one.

Cannot edit one record on linked table write conflict

We have a linked table in our Access 2010 database, the backend is SQL Server 2012, via an ODBC connection. The table is indexed (unique, non clustered) on a single field, the record's identifier.
The issue is that the odd record throws a 'write conflict - record changed by another user' type error when it is edited through the Access front end, but can be edited directly in SQL. Other records are fine. It's not the same record each day. The whole situation is a complete mystery to me so here are all the fact, maybe someone can make a coherent picture out of this.
The error message takes two different forms, depending how the edit is attempted. The normal functioning of the front end does it by opening a DAO recordset with just the one record, doing a bunch of edits on different fields, then closing the recordset and setting all object variables back to nothing. That produces first the "Write Conflict - This record has been changed by another user since you started editing it." error, with "Drop changes" or "Copy To Clipboard" as the options." It is then followed up with error 3197 "The Microsoft Access database engine stopped the process because you and another user attempted to change the same data at the same time."
If I just open the table in Access and manually try to change the record, I get the write conflict version of the error only. (Needless to say, I have confirmed that no other users are in the table at all, let alone the record.)
I can edit the row in SQL, and I can edit the row using a query in Access (via query design).
The data in the table is built each morning, and each day it seems to be a different record or two that is affected. It has only gone on for a few weeks, in a setup that has been running fine for about 6 months with no changes that could account for this (at least, that I can think of). The data build truncates the table and inserts all the records from scratch, and then rebuilds the index.
Here are some things I've tried:
Decompiling the database, compact and repair, relinking the table.
Linking the table into a brand new database that only has that one table in it.
Rebuilding the index.
Deleting the row and re-inserting it
Rebooting the SQL server (that was due to something else, but the problem still continued afterward.)
Opening the front end on a different computer.
Any help would be much appreciated!

Oracle SQL Developer DDL working on more than one schema at once

I am new to Oracle SQL Developer (about 1 month of use), having always used Toad. I have 2 almost identical schema set up - one to test older code, one to develop a modified versions. I have 2 different connections set up - one to each schema, with separate user names for each one.
But when I delete a table or column from the schema in one connection, it is also deleted or changed in the other.
This happens if I right-click on the table or field in the Connection explorer panel, or if I open a SQL Script saved to disk. If I open a SQL script, I even see a pop-up that asks me what connection to use, but if I select one, it still makes changes to both. Even if I only have one of the two connections open, the script will still change design in both of the connections.
The only way I can be sure to make changes to just one of the two is to right-click on the connection name in the Explorer panel, and open a new SQL Worksheet. The worksheet is then named for the connection and just makes changes to it.
This is not the behavior I was expecting, and I'm facing many hours of work to get the definitions of the 2 schema back to where I need them to be. I am wondering if there is some key concept or distinction I am missing or if there is some way the database(s) are set up that is enabling this to happen.
In case you never found the answer for your question. This is my understanding:
The database may have several schemas. The schema is not a separate database, it is a grouping of objects in that database. If you change something while in one schema, you are really changing it in the database, not just the schema. I hope this helps.
Are you just trying to test things in one schema? It sounds like you may want to have a Database and a TEST Database. You could test whatever you wanted in the TEST database and never have it change the real database.

Database cleanup

I inherited a SQL server database that is not well formatted. ( some consulting company came in to do the project and left without completing it)
the main issues I have with this database are:
Data types: a lot of tinyint and text types.
Tables are not normalized: some of the keys are names instead of seq ids.
A lot of tables that I am not sure are being used
a lot of stored procedures that i am not sure are being used
Badly named tables and stored procs
I also inherited the asp.net application that runs against this database.
I would like to clean this database up. I understand that changing the datatypes will have to happen at each table. for getting rid of all the extra tables and stored procs. what is the easiest way to do so.
any other tips to make it cleaner and smaller is appreciated.
I want to also mention that I have RedGate tools installed.( if that helps).
Thank you
Check out the Sql Server Data Tools they allow to create a project from a live database. Some of the things you can do in there is right click 'Find Usages' for the tables, views and functions.
So long as the previous developer used stored procedures and views rather than querying directly, it should find references to your project that way, without killing your project.
Also, for finding stored procedures that are not used, put in some basic logging at the top of each stored procedure in your application, after X amount of days, those that haven't been logged in your table are likely safe to remove, else a tedious search through your .NET code will find them.

Element X in the DataSet references an object missing from the Database

When first time I created my App, I created a Database using Microsoft SQL SERVER Management Studio and I connected my App with it.
I created another DB with the same tables and every thing but with diferent names and I let my App to connect to the second one because I want to make some changes and when I am trying to edit my DataSet with Wizard I get this tables page :
as you can see my app couldn't find the right tables and when I am trying to select LastWork table as in the pic, it will make the table name in the DataSet LastWork1.
How I can fix this problem? and let it find the right tables
I've seen this problem when using copies of databases as well, after pointing to a different connection in the settings area of the project properties. The XSD evidently hard codes each DbObjectName with the name of the database and schema in use at design time. One approach to fixing it is to open the wizard for the appropriate dataset, uncheck the red-x objects with the missing references, close the wizard, then re-open it and re-select the objects that are needed. This is not ideal in a large xsd if many findby queries, custom columns, etc. have been added. So an alternative is to do a find and replace on the database name within the XSD itself.
Interestingly, my experience has been that an application runs fine when the connection string points to a differently named but otherwise identical database.

Resources