troubleshooting Question

SQL Server SMO Executing SQL scripts with parameters vb.net c# visual studio

Avatar of talker2004
talker2004Flag for United States of America asked on
.NET ProgrammingC#Microsoft SQL Server 2005
1 Comment1 Solution2023 ViewsLast Modified:
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
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros