Creazione db in msde con file.sql

martedì 15 marzo 2005 - 13.27

trinity Profilo | Guru

Ragazzi con un tool di msde ho creato un file .sql contenente tutti i dati per creare il database,tabelle,indici ed utenti in msde,

c'è un modo in vb net di far leggere questo file ed eseguirlo con la semplice ExecuteNonquery dopo aver ovviamente installato il server sql?

Oppure devo scriverlo manualmente?

Sto facendo delle prove, mi sapete dare una dritta?

Ciao
Fabio

trinity Profilo | Guru

Ciao Coach, pensavo pure io così ma se non mi sono sbagliato nello script ci sono anche delle stored procedure, anke se è lungo ti posto lo script mi puoi solo all'inizio e fino alla creazione del database controllare e dirmi come posso lanciare le stored?

lo script te lo passo così come si è generato:

sql = "if not exists (select * from master.dbo.syslogins where loginname = N'invoice1')" & _
"BEGIN" & _
"declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'invoice1', @loginlang = N'Italiano'" & _
"if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)" & _
"select @logindb = N'master'" & _
"if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')" & _
"select @loginlang = @@language" & _
"exec sp_addlogin N'invoice1', null, @logindb, @loginlang, @sid = 0x9FAF506FE1DDD644B929210921356913" & _
"End" & _
"GO" & _
"if not exists (select * from master.dbo.syslogins where loginname = N'sa')" & _
"BEGIN" & _
"declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'master', @loginlang = N'Italiano'" & _
"if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)" & _
"select @logindb = N'master'" & _
"if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')" & _
"select @loginlang = @@language" & _
"exec sp_addlogin N'sa', null, @logindb, @loginlang, @sid = 0x01" & _
"End" & _
"GO" & _
"if not exists (select * from master.dbo.syslogins where loginname = N'BUILTIN\Administrators')" & _
"exec sp_grantlogin N'BUILTIN\Administrators'" & _
"exec sp_defaultdb N'BUILTIN\Administrators', N'master'" & _
"exec sp_defaultlanguage N'BUILTIN\Administrators', N'Italiano'" & _
"GO" & _
"CREATE DATABASE [invoice11] ON (NAME = N'invoice11_dat', FILENAME = N'C:\Programmi\Microsoft SQL Server\MSSQL\Data\invoice11.mdf' , SIZE = 2, FILEGROWTH = 10%) LOG ON (NAME = N'invoice11_log', FILENAME = N'C:\Programmi\Microsoft SQL Server\MSSQL\Data\invoice11.ldf' , SIZE = 2, FILEGROWTH = 10%)" & _
"GO" & _
"exec sp_dboption N'invoice1', N'autoclose', N'true'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'bulkcopy', N'true'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'trunc. log', N'true'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'torn page detection', N'true'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'read only', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'dbo use', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'single', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'autoshrink', N'true'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'ANSI null default', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'recursive triggers', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'ANSI nulls', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'concat null yields null', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'cursor close on commit', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'default to local cursor', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'quoted identifier', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'ANSI warnings', N'false'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'auto create statistics', N'true'" & _
"GO" & _
"exec sp_dboption N'invoice1', N'auto update statistics', N'true'" & _
"GO" & _
"if( ( (@@microsoftversion / power(2, 24) = 8) and (@@microsoftversion & 0xffff >= 724) ) or ( (@@microsoftversion / power(2, 24) = 7) and (@@microsoftversion & 0xffff >= 1082) ) )" & _
"exec sp_dboption N'invoice1', N'db chaining', N'false'" & _
"GO" & _
"if not exists (select * from dbo.sysusers where name = N'dbo' and uid < 16382)" & _
"EXEC sp_grantdbaccess N'sa', N

trinity Profilo | Guru

Ciao Coach, pensavo pure io così ma se non mi sono sbagliato nello script ci sono anche delle stored procedure, anke se è lungo ti posto lo script mi puoi solo all'inizio e fino alla creazione del database controllare e dirmi come posso lanciare le stored?

lo script te lo passo così come si è generato:

sql = "if not exists (select * from master.dbo.syslogins where loginname = N'invoice1')" & _
"BEGIN" & _
"declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'invoice1', @loginlang = N'Italiano'" & _
"if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)" & _
"select @logindb = N'master'" & _
"if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')" & _
"select @loginlang = @@language" & _
"exec sp_addlogin N'invoice1', null, @logindb, @loginlang, @sid = 0x9FAF506FE1DDD644B929210921356913" & _
"End" & _
"GO" & _
"if not exists (select * from master.dbo.syslogins where loginname = N'sa')" & _
"BEGIN" & _
"declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'master', @loginlang = N'Italiano'" & _
"if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)" & _
"select @logindb = N'master'" & _
"if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')" & _
"select @loginlang = @@language" & _
"exec sp_addlogin N'sa', null, @logindb, @loginlang, @sid = 0x01" & _
"End" & _
"GO" & _
"if not exists (select * from master.dbo.syslogins where loginname = N'BUILTIN\Administrators')" & _
"exec sp_grantlogin N'BUILTIN\Administrators'" & _
"exec sp_defaultdb N'BUILTIN\Administrators', N'master'" & _
"exec sp_defaultlanguage N'BUILTIN\Administrators', N'Italiano'" & _
"GO" & _
"CREATE DATABASE [invoice11] ON (NAME = N'invoice11_dat', FILENAME = N'C:\Programmi\Microsoft SQL Server\MSSQL\Data\invoice11.mdf' , SIZE = 2, FILEGROWTH = 10%) LOG ON (NAME = N'invoice11_log', FILENAME = N'C:\Programmi\Microsoft SQL Server\MSSQL\Data\invoice11.ldf' , SIZE = 2, FILEGROWTH = 10%)" & _
"GO" & _
"exec sp_dboption N'invoice1', N'autoclose', N'true'" & _
"GO" & _

trinity Profilo | Guru

Ciao Coach, pensavo pure io così ma se non mi sono sbagliato nello script ci sono anche delle stored procedure, anke se è lungo ti posto lo script mi puoi solo all'inizio e fino alla creazione del database controllare e dirmi come posso lanciare le stored?

lo script te lo passo così come si è generato:

sql = "if not exists (select * from master.dbo.syslogins where loginname = N'invoice1')" & _
"BEGIN" & _
"declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'invoice1', @loginlang = N'Italiano'" & _
"if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)" & _
"select @logindb = N'master'" & _
"if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')" & _
"select @loginlang = @@language" & _
"exec sp_addlogin N'invoice1', null, @logindb, @loginlang, @sid = 0x9FAF506FE1DDD644B929210921356913" & _
"End" & _
"GO" & _
"if not exists (select * from master.dbo.syslogins where loginname = N'sa')" & _
"BEGIN" & _
"declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'master', @loginlang = N'Italiano'" & _
"if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)" & _
"select @logindb = N'master'" & _
"if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')" & _
"select @loginlang = @@language" & _
"exec sp_addlogin N'sa', null, @logindb, @loginlang, @sid = 0x01" & _
"End" & _
"GO" & _
"if not exists (select * from master.dbo.syslogins where loginname = N'BUILTIN\Administrators')" & _
"exec sp_grantlogin N'BUILTIN\Administrators'" & _
"exec sp_defaultdb N'BUILTIN\Administrators', N'master'" & _
"exec sp_defaultlanguage N'BUILTIN\Administrators', N'Italiano'" & _
"GO" & _
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5