smo

Create failed for database , SMO,C#

﹥>﹥吖頭↗ 提交于 2019-12-24 07:09:54
问题 I am trying to create a new database programmatically using SMO (c#). I am working on SQL Server 2005. This is the code : ServerConnection connection = new ServerConnection(serverName, userName, password); Server sqlServer = new Server(connection); Database newDB = new Database(sqlServer, databaseName); newDB.Create(); I get the exception : "Create failed for database." What could be the problem and how can I create a new DB? thanks... 回答1: I tried this: with a sysadmin user, everything works

Programmatically getting SQL Cluster Virtual Name

送分小仙女□ 提交于 2019-12-24 04:32:21
问题 I have written a Windows service to collect information from all of our SQL servers. The service gets installed onto each server, and utilizing WMI and SMO, inserts relevant system information back to a central database. In order to get the SQL information, I use the following c# code: List<Server> sqlServers = new List<Server>(); //List of Smo.Server objects string registrySubKey = @"SOFTWARE\Microsoft\Microsoft SQL Server"; string registryValue = "InstalledInstances"; try { RegistryKey rk =

Folder Browser Dialog from remote machine perspective like the one SSMS uses

雨燕双飞 提交于 2019-12-24 03:02:03
问题 I'm creating a maintenance tool and I need to let the user to select a file location for new databases. I would use the FolderBrowserDialog except that I want to show the user the directory structure from the point of view of the machine that SQL Server is actually on rather than the client the tool is being run from. I know SSMS does this whenever you are selecting backup locations, so I'm wondering if the dialog it uses is available or if there's a way to make the FolderBrowserDialog behave

Use all backup sets to restore database with SMO

百般思念 提交于 2019-12-24 00:56:56
问题 My problem is really simple. I have a .bak file that contains one or more backup set. When I'm using SMO to restore the database with this .bak file, it only takes the first backup set to do its work. It seems to ignore the remaining sets. Why's that ? See my code : //Sets the restore configuration Restore restore = new Restore() { Action = RestoreActionType.Database, Database = _databaseToRestore.DatabaseName, ReplaceDatabase = true }; restore.Devices.Add(new BackupDeviceItem(_backupFilePath

C# SMO and SqlEnum references error

流过昼夜 提交于 2019-12-23 19:21:34
问题 I am doing a C# project by VS2013 which is using smo object. I installed Install-Package Microsoft.SqlServer.Scripting Install-Package Microsoft.SqlServer.SqlEnum.dll by Nuget and included using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo.Agent; but getting the following error Error 9 Assembly 'Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' uses 'Microsoft.SqlServer

Sql SMO: How to get path of database physical file name?

喜你入骨 提交于 2019-12-23 09:49:19
问题 I am trying to return the physical file path of a database's mdf/ldf files. I have tried using the following code: Server srv = new Server(connection); Database database = new Database(srv, dbName); string filePath = database.PrimaryFilePath; However this throws an exception "'database.PrimaryFilePath' threw an exception of type 'Microsoft.SqlServer.Management.Smo.PropertyNotSetException' - even though the database I'm running this against exists, and its mdf file is located in c:\Program

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

亡梦爱人 提交于 2019-12-23 05:28:01
问题 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 sqlserver2008 installed) in this actually i have sql2008 as default instance and sqlexpress(2005) as named instance... But it shows only one instance rkwrk3-vm-sr

Using SMO to script PARTIAL data content (only rows matching a WHERE clause)

≡放荡痞女 提交于 2019-12-23 02:18:56
问题 I use SMO to fill a SQL Compact database with the data of a SQL server database. Here is the code I actually use: foreach(Table l_tblCurrent in l_dbDatabase.Tables) { if(l_tblCurrent.IsSystemObject) continue; ScriptingOptions l_scOptions = new ScriptingOptions(); l_scOptions.NoIdentities = true; l_scOptions.NoCollation = true; l_scOptions.NoCommandTerminator = true; l_scOptions.NoFileGroup = true; l_scOptions.ScriptSchema = true; l_scOptions.ScriptData = true; foreach(string l_strCurrent in l

Using SMO to get create script for table defaults

不羁岁月 提交于 2019-12-22 08:13:14
问题 I'm trying to create a database scripter tool for a local database I'm using. I've been able to generate create scripts for the tables, primary keys, indexes, and foreign keys, but I can't find any way to generate create scripts for the table defaults. For indexes, it's as easy as foreach (Index index in table.Indexes) { ScriptingOptions drop = new ScriptingOptions(); drop.ScriptDrops = true; drop.IncludeIfNotExists = true; foreach (string dropstring in index.Script(drop)) { createScript

What's the fastest method to check SQL server availability?

一个人想着一个人 提交于 2019-12-21 17:01:46
问题 What's the best method to check if SQL server exists or not? I'm trying Microsoft.SqlServer.Management.Smo.Server.PingSqlServerVersion() and it works fine if server exists and available. But it kinda pretty slow, if there is no such a server. Is there any fast enough method to check without even defining user credentials (only the server name), if a server exists? What do you recommend to use? 回答1: You could just use TcpClient class to query the server and check if a specific port is open,