Avatar of talker2004
talker2004
Flag 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;
.NET ProgrammingC#Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Bob Learned

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck