Link to home
Start Free TrialLog in
Avatar of talker2004
talker2004Flag for United States of America

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\MyNewDatabase.mdf' , SIZE = 2048KB , FILEGROWTH = 1024KB )
 LOG ON
( NAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MyNewDatabase_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MyNewDatabase _log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)

EXEC dbo.sp_dbcmptlevel @dbname=N'MyNewDatabase ', @new_cmptlevel=90;

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [MyNewDatabase ].[dbo].[sp_fulltext_database] @action = 'disable'
end;
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial