Hi,I have a VbScript file that has oSQLServer.Connect statement using windows authentication. I am trying to pass the servername as parameter from command line. cscript ScriptJobs.vbs KIRAN\SECONDARYthis value KIRAN\SECONDARY should be passed as the servername in VBScript. I have the following codeDim ArgObjDim ServerNameSet ArgObj=Wscript.ArgumentsSet ServerName=ArgObj.Item(0)Dim oSQLServer Dim oStream Set oSQlServer = CreateObject("Wscript.SQLDMO.SQLServer") Set oStream = CreateObject("ADODB.Stream") oSQLServer.LoginSecure=TrueoSQLServer.Connect "& ServerName"Dim idStep Dim ScriptJob Dim CountJobs Dim JobName Dim ScriptAllJobs For Each oJob In oSQLServer.JobServer.Jobs CountJobs = oSQLServer.JobServer.Jobs.Count Next For idStep = 1 To CountJobs JobName = oSQLServer.JobServer.Jobs.Item(idStep).Name ScriptJob = oSQLServer.JobServer.Jobs.Item (idStep).Script(4, "C:\" & JobName & ".sql") ScriptAllJobs = ScriptAllJobs & ScriptJob Next oStream.Open oStream.WriteText (ScriptAllJobs) oStream.SaveToFile ("C:\SQLAllScripts.sql"), 2 oStream.Close oSQLServer.DisConnect Set oStream = Nothing Set oSQLServer = Nothing Set ArgObj=NothingHowever, the parameter that i pass in command line is not being taken as input into the ServerName. Please help me out with this
↧
passing parameters to a vbs file in command line
↧
how to use SQLDMO_SCRIPT_TYPE options in code
Hi,I have the following code that scripts out all agent jobs on a server. I want the generated script to include If not exists condition coz i either want to skip or overwrite existing jobs.Dim ArgObjDim xDim ServerNameSet ArgObj=Wscript.Argumentsx=ArgObj.Item(0)ServerName=Mid(x,3)Wscript.Echo(ServerName)Dim oSQLServer Dim oStream Set oSQlServer = CreateObject("SQLDMO.SQLServer") Set oStream = CreateObject("ADODB.Stream") oSQLServer.LoginSecure=TrueoSQLServer.Connect ServerNameDim idStep Dim ScriptJob Dim CountJobs Dim JobName Dim ScriptAllJobsFor Each oJob In oSQLServer.JobServer.Jobs JobName = oJob.Name if (InStr(UCase(JobName), "MIRRORING") > 0) Then Wscript.Echo("Skipping Job"&JobName) else ScriptJob = Replace(oJob.Script(4,"C:\"& JobName &".sql") , ServerName, "(local)") ScriptAllJobs = ScriptAllJobs & ScriptJob End If NextoStream.Open oStream.WriteText (ScriptAllJobs) oStream.SaveToFile ("C:\SQLAllScripts.sql"), 2oStream.Close oSQLServer.DisConnectSet oStream = Nothing Set oSQLServer = Nothing Set ArgObj=NothingWhere and how do i implement in this code?
↧
↧
Error: This cache contains no result sets, or the current result set contains no rows.
Hi all,
Does anyone know what this error means, what causes it and how to fix it?
Exception:
System.Runtime.InteropServices.COMException (0x80045026): [SQL-DMO]This cache contains no result sets, or the current result set contains no rows.
at SQLDMO.QueryResults.GetColumnString(Int32 Row, Int32 Column)
at Mbr.DbGet.DbRestorer.RestoreDatabase()
at Mbr.DbGet.DbRestorerCollection.RestoreAll()
I have created an application that restores a given database. This application works fine on one machine but throws this error on a second machine.
I can't find anything about this error on either google or MSDN.
Can anyone help?
Kindest regards
jeanangeo
↧
retrieving tables from view with SMO
How can I retrieve tables names used in a view by SMO?I can get the columns but I need the tables used in the viewthx
↧
Retreive an error for an UPDATE SQL Statement
HiI wrote a VB6 program using SQL-DMO. Everything works fine except I don't know how to get the real result of an UPDATE SQL Statement.For exemple:UPDATE MY_TABLE SET CLt_Name=new_name where Clt_ID=myIDWhatever the myID value (existing in my DB or not) this SQL command run from VB60 (ExecuteWithMessage) will produce the same result: No error and number of row is zero.How can I detect an error if myID is wrong??
↧
↧
Setting article properties for a publication using RMO in C# .NET
Hello everyone i am using transaction replication with push subscription. I am developing a UI for replication using RMO in C#.NET between different instances of the same database [b]within same machine[/b] holding similar schema and structure. I am using Single subscriber and multiple publisher topology. During creation of publication i want to set a few article properties such as Keep the existing object unchanged and allow schema changes at subscriber to false and copy foriegn key constarint to true. How do i set the article properties using RMO in C# .NET. I am using Visual Studio 2008.I also want to know as how we can select all the objects including Tables,Views,Stored Procedures for publishing. [b]I could do it for one table but i want to select all the tables at one stretch.[/b] This is the code snippet i used. TransArticle ta = new TransArticle(); ta.Name = "Article_1"; ta.PublicationName = "TransReplication_DB2"; ta.DatabaseName = "DB2"; ta.SourceObjectName = "person"; ta.SourceObjectOwner = "dbo"; ta.ConnectionContext = conn; ta.Create();
↧
DMO UseBulkCopyOption
GuysWe have just migrated a database to SQL Server 2008 from SQL 2000 SP4, there is an in house application that uses DMO to bulk copy data into the load tables.We are expereincing major performance issues when we switch the database to simple recovery model and a lot of instances in the event logs/SQL logs where the recovery model is being switched to RECMODEL_70BACKCOMP then back to Simple. This is not the case when we switch to Bulk Logged.We have prety much concluded that the issue is to do with our app, however not being too familiar with DMO (the Dev left many moons ago) I am after some advice.At the moment the UseBulkCopyOption Property is set to true, what would be the repercussions of setting this to false and would it potentially sole our issue.Any pointers on how to load lots of data quickly using .NET/SMO etc. would be appreciated.Also does anyone know if using the BULK INSERT T-SQL would have similar issues to the DMO bulk copy that we are seeing?Cheers in advanceJQ
↧
Refresh PivotTables in MS Excel 2007 with OLE Automation
Hi,I need to update a pivot table that resides on a Microsoft Excel worksheet.I created a stored procedure dbo.USP_DMO_EXCEL_Pivot_RefreshTable(link: [url]http://www.ugiss.org/Content/Article/Aggiornare-una-tabella-pivot-di-Microsoft-Excel.aspx[/url]) that uses OLE Automation (sp_OA*) to refresh, every night (without open the Excel file), the pivot table data in Microsoft Excel worksheet.The stored procedure works well in this enviroment:- OS Windows Server 2003- Office 2003- SQL Server 2008The stored procedure does not work with:- OS Windows Server 2008 64-bit or Windows 7 64-bit- Office 2007- SQL Server 2008 64-bitThe pivot table connecting to SQL Server with an ODBC connection (32 bit).The Excel file will open correctly, bit I get an error during execution method "RefreshTable" in the following line of code:[code="other"]Exec sp_OAMethod @objWorkSheet PivotTables('Pivot_Name').RefreshTable[/code]The execution of stored procedures will not be completed, the only way (to stop it) is to interrupt forcefully the task "EXEC.EXE *32".When I forced to close the task, in SSMS I get the following error:-2146827284 Unable to find Microsoft Office Excel PivotTables property for the class Worksheet. C:\Program Files (x86)\Microsoft Office\Office12\1040\0 XLMAIN11.CHM Message 50000, Level 16, State 1, Server <name> USP_DMO_Excel_Pivot_RefreshTable procedure, line 369 Whilst Error: Return object workbooks, Could not find property PivotTables for Class Worksheet I also installed the 2007 Office System Driver: Data Connectivity Components ([url]http://www.microsoft.com/downloads/details.aspx?familyid=7554f536-8c28-4598-9b72-ef94e038c891&displaylang=en[/url]) but without improvement.Any suggestions? Thanks a lot!
↧
change logical names in SMO
Hello All,I am having issues changing the logical names post restore.I am restoring a database with SMO (using VB.NET). After the database has been restored, I am changing the logical names of the files to match the new database name by using an alter database statement query.Before the restore is performed.I am doing a validation for valid database names (i.e. valid windows OS filenames) via a regex pattern before performing the restore. The problem is, the T-SQL that I am executing after the restore is not adequately compensating for special characters in the database name (i.e. filename). Here are the statementsTaken from SMO SQL capture during a VB.NET application run. SMO changed the database name to DBA[]] instead of DBA[]. This works.[code="sql"]RESTORE DATABASE [DBA[]]] FROM DISK = N'C:\DBA-NoPassword.bak' WITH MOVE N'DBA' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\DBA[].mdf', MOVE N'DBA_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\DBA[]_log.ldf', UNLOAD, REPLACE, STATS = 1[/code]Trying to change the logical names, post restore.Corrected SQL statement that works:[code="sql"]ALTER DATABASE [DBA[]]] MODIFY FILE(Name = [DBA], NEWNAME = [DBA[]]])[/code]Uncorrected statement that does not work:[code="sql"]ALTER DATABASE [DBA[]] MODIFY FILE(Name = [DBA], NEWNAME = [DBA[]])[/code]As you can see, I had to add an extra "]" at the end of the database name "DBA[]" to make the statement work. It is as if the extra "]" is acting as an escape character for the final ]. My question is.. if SMO can correctly restore a database name which contains "[]" in the name, then a SMO operation should be able to change the logical names. I have been googling and have not been able to find SMO code to incorporate into my VB.NET app, and I do not want to create special conditions for each special character that may be used in a database name. I also do not want to limit the special characters either.Did I miss something on my google search for how to change logical names using SMO?Let me know if you guys have any ideas.update:I am aware that when I create a new database, it will create logical names based upon the database name. When creating a new database via a restore, it uses the logical names embedded in the backup headers. I cannot override the default logical names during the restore, and I need the move option because the remote server I am restoring to does not contain the same file paths as the backup file.My question is for already existing databases, that are being restored, which already have logical names different than the database name.Thanks,DougUpdate #2:I think a workaround solution might be for me to first drop the database, create a new database, and then do a restore with move to option. Sure seems like a lot of work. Please let me know if I can change logical names with SMO...
↧
↧
script out all the jobs in sql server 2008 excluding the mirroring jobs
Hi,I want to script out all the jobs in sql server 2008 excluding the mirroring jobs to a file whose location is passed as a parameter. Can you please let me know how to do this.Thanks,Kiran
↧
Looking for MySQL expert to Skype with us!
We are looking for a MySQL consultant who is expert in writing conditional SELECT statements using the "CASE WHEN" structure that we can Skype screen share with who will advise us until we have constructed an SQL statement that delivers the desired results.Thanks in advance,Tess
↧
object with managedDTS
hi, I try to create this object, but I Had error :$obj= new-object Microsoft.SQLServer.ManagedDTS "$ServerName"error - "can't find type [ Microsoft.SQLServer.ManagedDTS ] : make sure the assembly containing this type is loaded "thank's for the help.
↧
Running .sql file using C# .Net - Accents Problem
Hello, I have this small app to run a batch of .sql files on multiple databases. When the .sql files have accents, (most of them comments) I get this error:[img]http://img5.imageshack.us/img5/7030/sinog.jpg[/img]The thing is that I can't remove the accents I must leave them there... So if anyone has any experience or advice to share it would be much appreciated.This is a example of the code im using:using System.Data.SqlClient;using System.IO;using Microsoft.SqlServer.Management.Common;using Microsoft.SqlServer.Management.Smo; namespace ConsoleApplication1{ class Program { static void Main(string[] args) { string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True"; FileInfo file = new FileInfo("C:\\myscript.sql"); string script = file.OpenText().ReadToEnd(); SqlConnection conn = new SqlConnection(sqlConnectionString); Server server = new Server(new ServerConnection(conn)); server.ConnectionContext.ExecuteNonQuery(script); } }
↧
↧
update access to sql server
I would like 'power' users to be able to run queries and update selected tables, I would prefer for this to occur on the web. Can you tell me how to accomplish this task using either sql server 2005 and/or sql server 2008 R2?
↧
load assembly - error
hi,I load assembly of managedts.it's work great with the new version of sql 10.5 .but when I try to use this spesfic assembly I get a ERROR Version.mybe someone had exprience about this.thank's
↧
SMO within SSIS Script Task - User.Drop() causes error at runtime.
I am having issues with the following code within a SSIS package. It is designed to drop all database users before a restore operation commences and following a kill all connections script. The issue I am running into is that at run-time this code generates an error saying the collection has changed after the first user is dropped which causes the script to exit. Anyone have any ideas what is wrong here? Of note, this is running against a SQL 2000 database not a SQL 2005 database.Any help you can provide would be greatly appreciated.Scott[code]' Microsoft SQL Server Integration Services Script Task' Write scripts using Microsoft Visual Basic' The ScriptMain class is the entry point of the Script Task.' References Used, includes defaults:' Microsoft.SqlServer.ConnectionInfo' Microsoft.SqlServer.ManagedDTS' Microsoft.SqlServer.ScriptTask' Microsoft.SqlServer.Smo' Microsoft.Vsa' System' System.Data' System.Windows.Forms'Imports SystemImports System.DataImports System.MathImports Microsoft.SqlServer.Dts.RuntimeImports Microsoft.SqlServer.Management.SmoPublic Class ScriptMain ' The execution engine calls this method when the task executes. ' To access the object model, use the Dts object. Connections, variables, events, ' and logging features are available as static members of the Dts class. ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure. ' ' To open Code and Text Editor Help, press F1. ' To open Object Browser, press Ctrl+Alt+J. Public Sub Main() Try Dim srvr As Server = New Server(Dts.Variables("DestinationServer").Value.ToString) Dim db As Database db = srvr.Databases(Dts.Variables("DestinationDB").Value.ToString) Dim usr As User For Each usr In db.Users ' Check to see if the user is a system object, if not then drop the user If Not usr.IsSystemObject Then usr.Drop() End If Next Dts.TaskResult = Dts.Results.Success Catch ex As Exception Dts.TaskResult = Dts.Results.Failure End Try End SubEnd Class[/code]
↧
Growth of transaction log
someone has script to monitor a Growth of transaction log in sqlserver/or link.thank's
↧
↧
ListAvailableSQLServers (SQL-DMO) deprecated
I understand that ListAvailableSQLServers is deprecated, but I cannot find what to replace it with.I see that SQL-DMO is replaced with SMO, but I do not see an equivalent method. code snippet below.Assistance greatly appreciated. SQLDMO.NameList oNames; SQLDMO.Application oSQLApp = new SQLDMO.Application(); oNames = oSQLApp.ListAvailableSQLServers();
↧
smo table script generation performance problem
Hello,I'm currently working on program for database compare. In this program I need to create scripts for databse objects. i found out that script generation is too slow but generating scripts using SSMS it's pretty fast. In one thread I have found, that SSMS uses for script generation SMO, but I couldn't find any suggestions for performance improvement. CollapseServer srv = new Server(new ServerConnection("SERVER", "USERID", "PASSWORD"));srv.SetDefaultInitFields(typeof(Table), true);Database db = srv.Databases[database];ScriptingOptions so = new ScriptingOptions();so.AllowSystemObjects = false;...db.PrefetchObjects(typeof(Table),so);...foreach(Table tb in db.Tables){ StringCollection sc = tb.Script(); . . .}Interesting is that db.PrefetchObjects(typeof(Table),so) has almost no effect for script generatino of tables, but is rapidlyincreases script generation of stored procedures.Can someone explain me, what kind of mechnizm SSMS uses for script generation, or is top secret informacion? :PRegardsRobert
↧
SMO performance issues!
Hi guys!I've used SMO in some my latest apps but I am really disappointed with performance! It is horrible slowly!Did you felt this issues also?What do you think!
↧