talker2004
asked on
SQL Server SMO Executing SQL scripts with parameters vb.net c# visual studio
I am using SMO to execute some SQL Scripts. I want to create some parameters inside of the sql script. An example would be everywhere there is a reference to the database name i want that to be variable or a parameter.
Would someone show me an example of using SMO from a .net language and setting parameters / values before executing the script. Here is one of our scripts. I want MyNewDatabase to be a variable and SMO to set the value before it executes the script.
-- CREATE THE MyNewDatabase DATABASE
CREATE DATABASE [MyNewDatabase] ON PRIMARY
( NAME = N'MyNewDatabase', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\ MyNewDatab ase.mdf' , SIZE = 2048KB , FILEGROWTH = 1024KB )
LOG ON
( NAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\ MyNewDatab ase_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\ MyNewDatab ase _log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)
EXEC dbo.sp_dbcmptlevel @dbname=N'MyNewDatabase ', @new_cmptlevel=90;
IF (1 = FULLTEXTSERVICEPROPERTY('I sFullTextI nstalled') )
begin
EXEC [MyNewDatabase ].[dbo].[sp_fulltext_datab ase] @action = 'disable'
end;
Would someone show me an example of using SMO from a .net language and setting parameters / values before executing the script. Here is one of our scripts. I want MyNewDatabase to be a variable and SMO to set the value before it executes the script.
-- CREATE THE MyNewDatabase DATABASE
CREATE DATABASE [MyNewDatabase] ON PRIMARY
( NAME = N'MyNewDatabase', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\
LOG ON
( NAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\
EXEC dbo.sp_dbcmptlevel @dbname=N'MyNewDatabase ', @new_cmptlevel=90;
IF (1 = FULLTEXTSERVICEPROPERTY('I
begin
EXEC [MyNewDatabase ].[dbo].[sp_fulltext_datab
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.