Administrator.NewDatabaseBasic()

Mar 2, 2010 at 9:38 AM

When i want to create new database with Administrator.NewDatabaseBasic() program crashes. I get "Invalid object name 'information_schema.tables'." error. I am using sql server 2005 express edition. May be it is about my case setting but how can fix this error.

Thanks.

Coordinator
Mar 3, 2010 at 7:53 AM

Total generation needs to remove all the tables (and constraints) in the database first. in order to do that uses this script:

declare @schema nvarchar(128), @tbl nvarchar(128)
DECLARE @sql nvarchar(255)
 
declare cur cursor fast_forward for 
select distinct table_schema, table_name
from information_schema.tables where table_type = 'BASE TABLE'
open cur 
    fetch next from cur into @schema, @tbl
    while @@fetch_status <> -1 
    begin 
        select @sql = 'DROP TABLE ' + @schema + '.' + @tbl + ';'
        exec sp_executesql @sql 
        fetch next from cur into @schema, @tbl
    end 
close cur 
deallocate cur

 That's why it fails if you have no information_schema.tables.

Look at the source code of NewDatabaseBasic here http://signum.codeplex.com/SourceControl/changeset/view/25903#510335 

        public static void NewDatabaseBasic()
        {
            RemoveAllScript().TryDoC(a=>a.ExecuteLeaves());
            CreateTablesScript().TryDoC(a => a.ExecuteLeaves());
            InsertEnumValuesScript().TryDoC(a => a.ToSimple().ExecuteNonQuery());
            if (Schema.Current.Tables.ContainsKey(typeof(TypeDN)))
            {
                InsertTypesScript().TryDoC(a => a.ToSimple().ExecuteNonQuery());
                Schema.Current.CacheTypeTable(); 
            }
        }

Maybe you can call the small methods independently and skip the RemoveAllScript (and do it by yourself).
This solution will need to be changed in SF 2.0 because Administrator infrastructure have changed a little bit. 
Hope it helps. 
Olmo
Mar 3, 2010 at 9:23 AM
Edited Mar 3, 2010 at 9:23 AM

Hello,

Now Administrator.CreateTablesScript().ExecuteLeaves() crashes with "Column, parameter, or variable #3: Cannot find data type BİGINT." error. I think it should be "bigint" or "BIGINT".

Here is my create tables script:

CREATE TABLE tlCustomerDN(
    Id INT IDENTITY NOT NULL PRIMARY KEY,
    ToStr NVARCHAR(200) NULL,
    Ticks BİGINT NOT NULL,
    Name NVARCHAR(200) NULL,
    LastName NVARCHAR(200) NULL,
    DateOfBirth DATETİME NOT NULL
)

Coordinator
Mar 3, 2010 at 7:45 PM

I was completely lost looking for BIGINT + Sql Server express and then I've looked at the small dot over the i of your BİGINT. Why is not in INT? And why is inDATETİME.

Then I've found this: http://www.i18nguy.com/unicode/turkish-i18n.html

Are you Turkish ??

May 4, 2010 at 6:19 PM

Sorry for late answer. Yes I am Turkish. We have both 'I' and 'İ' int he alphabet.

Coordinator
May 15, 2010 at 11:36 PM

We have solved it, our sql builder did ToUpper instead of ToUpper(CultureInfo.InvariantCulture).

Will be fixed for SF 2.0