smo

How to get the list of SqlInstances of a paricular machine

Can anyone tell me how to get remote Sqlserver instances using c# and SMO or any api? I have a remote server name "RemoteMC", which has 2 instances of sql server: "RemoteMc" and "RemoteMC\sqlexpress" I try to get the instances in code like this: Server srv=new Server("RemoteMC"); DataTable dt=SmoApplication.EnumAvailableSqlServer(true...

what is the CLSID and PROG ID of Microsoft.sqlserver.Management.Smo

Hi Can any Body tell me wher can i get CLSID and ProgID of Smo library?? As for DMO it is givenn in a Header file by Microsoft.But i am not finding any Header file related to smo. What is the CLSID and ProgID of Smo ?? ANy Hep in this regard greately Appreciated. Thanks in advance. ...

How to list available instances of SQL Servers using SMO in C#?

Hi Can anybody explain me what I wrong I am doing in the following piece of code: DataTable dt=SmoApplication.EnumAvailableSqlServer(true); Server sr = new Server("Test"); foreach(DataBase db in sr.DataBases) { Console.WriteLine(db["name"]); } It gives an exception in sr.Databases that can not be connected. ...

SmoApplication.EnumAvailableSqlServers() does not list default instance if sqlexpress is in same machine where SQLSERVER2008 installed

Hi I am using SMO to find available sqlservers of a network.But in one machine where i running application it doesnot give Default instance name but for all other machines it gives the named and default instance wil be showing. Observe my Scenario. Ex: Machine Name :rkwrk3-vm-sr (local machine from where i am running app in which ...

How to Connect to Sqlserver2008 using SMO any workaround has to be done???

I wrote this for finding the sql server instances on the local machine: using System; using System.Data; using Microsoft.SqlServer.Management.Smo; namespace Application3 { class Program { static void Main(string[] args) { string srvname = string.Empty; string srvnames = null; DataTable...

Transfer Database from SQL-Server 2005 to SQL-Server 2008

I have an existing application that transfers a Database from a source server to a target server via SMO "Transfer". We transfer only the data. Both SQL-Servers are 2005. Now we upgrade the target server to SQL-Server 2008. Will the transfer via SMO still work? ...

How to create database using SMO with everyone having permission?

I am trying to create a SQL Server Express database using SMO like so: Database db = new Database(server, dataSource); ... db.Create(); I am able to use the database fine. But, if someone else tries to copy the database, they get file permission errors. In looking under the security tab in windows explorer, I am the only one who has...

Alternatives to SMO, i.e. DML APIs for SQL Server?

I just learned I can't use SMO in ASP.NET without either SQL or a full SMO install on the application server. I'm not allowed to do that, so I can't use SMO. What other libraries do the same thing as SMO but don't require an MSI installer or COM registrations? I know I could send DDL to the server inside ADO.NET commands, but that is ...

Fixing Orphaned Users with SQL SMO?

Is there a way to fix an orphaned user in a SQL 2005/2008 database using SQL SMO? You can find orphaned users relatively easily by enumerating through the users and looking for an empty User.Login property: using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; public static IList<string> GetOrphaned...

Can't enumerate SQL Server 2008 Registered Servers with SMO

Hi there, I had SQL Server 2005 Management Studio installed on my workstation. I have since installed SQL Server 2008 workstation tools and removed the SQL Server 2005 tools. I am now writing a c# program which iterates my registered servers in management studio. Problem is, it is iterating through my old list in the 2005 tools (which h...

Drop all active database connections failed for Server when executing KillAllProcesses

I need to perform a database restore from my application. Before doing this, I want to kill all processes as follows: private void KillAllProcessesOnSMARTDatabases(Server targetServer) { targetServer.KillAllProcesses(SMART_DB); targetServer.KillAllProcesses(SMART_HISTORY_DB); targetServer.KillAllProcesses...

How to restore a database from C#

I have a SQL 2008 DB. I am running a form that backs that DB up, then tries to update it. If the update fails the idea is to restore that backup. Here is the code I am using to restore the backup. public void RestoreDatabase(String databaseName, String backUpFile, String serverName, String userName, String password) { Restore sqlRe...

c# and SMO - Get Message output such as "Table already exists" for logging.

Hi, I am using SQL Management objects to connect to SQL server. At the moment they contain simple "create table" commands for my example. I run this code twice on purpose to cause an error for "table already exists". However my events below are not getting triggered. Anyone got any ideas, how I can get hold of this message in my co...

SMO - Assembly dependencies

I need to use SMO to find out all the dependencies of a registered assembly (SQLCLR). How can I do that? Thanks, Nestor ...

How to display ndf files using SMO??

Hi I am using SMO to populate the list of database files log files. i am using filegroups but it displays only mdf and ldf files. I have ndf files also it is not dispalying ndf files?? what i have to do any suggestions plz??? string dbname = string.Empty, DatabaseInfo = string.Empty; Server srv = new Server(insta...

Executing queries with ExecuteWithResults using the BatchSeparator

We are using Smo.Server to run some SQL batches. For queries that create stored procedures or tables and contain the separator GO the following code works: server.ConnectionContext.ExecuteNonQuery(sql); But the following fails server.ConnectionContext.ExecuteWithResults(sql); For sql that doesn't change the database structure it se...

Single User after renaming an MS-SQL database

I am using help of SqlServer.Management.Smo to rename an attached MS-SQL database. Dim db As New Database = ActiveSQLServer.Databases(OLD_NAME) db.ExecuteNonQuery("ALTER DATABASE " & OLD_NAME & " SET SINGLE_USER WITH ROLLBACK IMMEDIATE") db.ExecuteNonQuery("ALTER DATABASE " & OLD_NAME & " MODIFY NAME = " & NEW_NAME) The problem is tha...

asp .net page to backup sql db

Hi guys, I'm trying to create an asp .net page to backup and download an mssql db from my remote host on a shared server. I tried using SMO to create a backup and save it the same folder as the .aspx page but it throws an access denied exception, I later found out that the sql server doesn't have permissions to write backups anywhere bu...

Using SMO, still no go... ConnectionContext.ExecuteNonQuery(script) can't understand "GO"

Hello! SQL Server 2008 Using all the correct references I dare say: System.Data.SqlClient; Microsoft.SqlServer.Management.Smo; Microsoft.SqlServer.Management.Common; Microsoft.SqlServer.Management.Sdk.Sfc; All compiles with no errors. I have stripped code down to almost zero for easy debugging. Connecting to server alright and so o...

Microsoft.SqlServer.Management.Sdk.Sfc.Urn

I have the SQL2008 version of SMO and although it uses this class internally I can't figure how to bring it into scope so I can declare variables to hold values of this type. Yes I know I could declare them as object but then I'd still be unable to cast them to pass typed parameters. What reference do I need to add to my project and w...