How do I change the collation for a CRM 2011 SQL database? - sql-server-2008-r2

I have a collection of CRM 2011 databases, all of which are installed on the same SQL server running SQL 2008 R2. One of those databases has a collation of Modern_Spanish_Cl_Al, while all of the others are set to Latin1_General_Cl_Al. I want all of them to be set to Latin1, so I would like to go back and fix the Spanish database to be like the others.
How do I change the database collation from Modern_Spanish_Cl_Al to Latin1_General_Cl_Al?
I tried doing it at the database level using the UI, but I received a million errors like:
The statistics 'TeamBase.fndx_Sync_VersionNumber' is dependent on database collation. The database collation cannot be changed if a schema-bound object depends on it. Remove the dependencies on the database collation and then retry the operation.
I tried going to the column level while also using the UI, but received a different error message:
Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created...
I am dealing with this issue in a test environment, so I am willing to experiment, and I realize that what I am trying to do might not be possible without breaking CRM.

Did you try creating a new DB with the correct collation
CREATE DATABASE DatabaseName COLLATE Latin1_General_Cl_Al;
And then Backup-Restore your DB with incorrect collation into the new one?
Should this work, you'll have to import a new organization based on your new database, using the Import Organization Wizard in the Deployment Manager.
edit
After looking into this, it seems quite hard to change collation, even when doing backup/restore.
Your only option if you want to change the collation on the database level seems to be an
ALTER DATABASE ... COLLATE
but that will only affect new objects. You would then have to use ALTER TABLE to change your existing tables.
In addition, because the collation specifies how data is sorted and stored, you need to export all your data and bring it in again (using BCP and BULK INSERT for instance).
To add to this, certain properties of a column prevents its collation from being changed (such as certain constraints and schema bound function references). If you do want to change the collation of the entire database, the easiest way is probably to script the database and create a new with the right collation and then shuffle the data into the new database.

Related

How to replicate rows into different tables of different database in postgresql?

I use postgresql. I have many databases in a server. There is one database which I use the most say 'main'. This 'main' has many tables inside it. And also other databases have many tables inside them.
What I want to do is, whenever a new row is inserted into 'main.users' table I wish to insert the same data into 'users' table of other databases. How shall I do it in postgresql? Similarly I wish to do the same for all actions like UPDATE, DELETE etc.,
I had gone through the "logical replication" concept as suggested by you. In my case I know the source db name up front and I will come to know the target db name as part of the query. So it is going to be dynamic.
How to achieve this? is there any db concept available in postgresql? Or I welcome all other possible ways as well. Please share me some idea on this.
If this is all on the same Postgres instance (aka "cluster"), then I would recommend to use a foreign table to access the tables from the "main" database in the other databases.
Those foreign tables look like "local" tables inside each database, but access the original data in the source database directly, so there is no need to synchronize anything.
Upgrade to a recent PostgreSQL release and use logical replication.
Add a trigger on the table in the master database that uses dblink to access and write the other databases.
Be sure to consider what should be done if the row alreasdy exists remotely, or if the rome server is unreachable.
Also not that updates propogated usign dblink are not rolled back if the inboking transaction is rolled back

How to retrieve data from Firebird DB with missing user collation?

I've got a Firebird DB (FDB file) that I can connect to just fine. However, one of the tables uses a user-defined collation, which apparently was defined via an fbintl_xyz.dll extension. That extension is not available to me.
Accessing that table consequently results in
COLLATION UTF8_XYZ for CHARACTER SET UTF8 is not installed
Is there any way around this?
I only need read access, and I don't care about collation support (ordering, upper case/lower case).

Data insert issue after migrating database from SQL Azure to SQL Server

I have a database on SQL Azure which has an identity primary.
After using SQL Server Import and Export Wizard, I transferred the data to my SQL Server 2008 R2 database.
My ASP.NET Application runs fine and reads the data. But When I try to insert a value in a table 'User', it gives me an error:
Cannot insert null in column 'UserId'.
The reason being that it is not able to generate the identity value.
How can I overcome this issue?
PS: I tried Generating the scripts from SQL Azure, but the SQL file is 500MB in size and my host does not allow that big a script to run.
Edit: using Entity Framework for data access. The UserId field has an IDENTITY property (1,1).
Edit Tried to create the schema from SQLAzure Migration tool and then used the import/export data to copy the data.
But the wizard does not maintain the relations amongst the rows.
The data import/export wizard doesn't preserve the whole structure of your database objects.
i.e. it will only copy the data, not the whole structure of the table that the data fits into - including identity and key definitions.
You could import the data, and then manually set all the primary keys and default fields to match your desired database definition, or you could connect to your Azure instance and use the generate script option to generate your schema in the 2008 database prior to copying.
But the real answer is that you should be using the Copy Database Wizard to accomplish this, which works fine with Azure. It was designed for this scenario.
The issue was the wizard was trying to insert primary key values, which is disabled by default. And without inserting the primary keys, the relationships can't be maintained, thus the whole issue.
To resolve this issue and do a foolproof migration, ensure that the new schema maintains all the identity columns.
When selecting the source and destination tables, for the specific tables, click on "Edit Mappings" and Check the "Enable identity insert" check box to enable insertion of primary key values, which keep the structure and relations intact.

libpq code to create, list and delete databases (C++/VC++, PostgreSQL)

I am new to the PostgreSQL database. What my visual c++ application needs to do is to create multiple tables and add/retrieve data from them.
Each session of my application should create a new and distinct database. I can use the current date and time for a unique database name.
There should also be an option to delete all the databases.
I have worked out how to connect to a database, create tables, and add data to tables. I am not sure how to make a new database for each run or how to retrieve number and name of databases if user want to clear all databases.
Please help.
See the libpq examples in the documentation. The example program shows you how to list databases, and in general how to execute commands against the database. The example code there is trivial to adapt to creating and dropping databases.
Creating a database is a simple CREATE DATABASE SQL statement, same as any other libpq operation. You must connect to a temporary database (usually template1) to issue the CREATE DATABASE, then disconnect and make a new connection to the database you just created.
Rather than creating new databases, consider creating new schema instead. Much less hassle, since all you need to do is change the search_path or prefix your table references, you don't have to disconnect and reconnect to change schemas. See the documentation on schemas.
I question the wisdom of your design, though. It is rarely a good idea for applications to be creating and dropping databases (or tables, except temporary tables) as a normal part of their operation. Maybe if you elaborated on why you want to do this, we can come up with solutions that may be easier and/or perform better than your current approach.

How to copy everything except data from one database to another?

In T-SQL (Microsoft SQL 2008), how can I make a new database which will have the same schemas, tables, table columns, indexes, constraints, and foreign keys, but will not contain any data from the original database?
Note: making a full copy, then removing all data is not a solution in my case, since the database is quite big, and such full copy will spend too much time.
See here for instructions: How To Script Out The Whole Database In SQL Server 2005 and SQL Server 2008
In SQL Management Studio, right click on the database and select "Script database as"
http://msdn.microsoft.com/en-us/library/ms178078.aspx
You can then use the script to create an empty one.
Edit : OP did say 2008
I use liquibase for this purpose. Just point liquibase to a different server and it will use your changelog to bring the second database up to date, schema wise. It has the added benefit that the changelog file gets stored in source control and so I can have tagged versions of it, allowing me to restore a database to what a specific version of my app is expecting.