- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
code 128 checksum c# Starting SQL Server and supporting services in a command batch in C#
Listing 2 Starting SQL Server and supporting services in a command batch Creating ANSI/AIM Code 128 In Visual C#.NET Using Barcode drawer for .NET Control to generate, create Code 128A image in VS .NET applications. www.OnBarcode.comRecognize Code-128 In C#.NET Using Barcode decoder for .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comcls echo on rem sc start w3svc sc start mssql$ss2k8 sc start reportserver$ss2k8 sc start sqlagent$ss2k8 sc start sqlbrowser sc start mssql$sqlexpress start msdtsServer start sqlwriter pause USS Code 39 Maker In Visual C#.NET Using Barcode drawer for .NET framework Control to generate, create Code39 image in VS .NET applications. www.OnBarcode.comCreate QR Code In Visual C# Using Barcode encoder for VS .NET Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications. www.OnBarcode.comIt s also possible to start SQL Server (or any service) using .NET factory classes, and I ll show you how to do that a bit later (in listing 4). Printing EAN128 In C#.NET Using Barcode creator for VS .NET Control to generate, create GS1 128 image in Visual Studio .NET applications. www.OnBarcode.comMatrix 2D Barcode Creator In Visual C# Using Barcode encoder for Visual Studio .NET Control to generate, create Matrix Barcode image in .NET applications. www.OnBarcode.comFinding visible SQL Server instances
Barcode Generator In C#.NET Using Barcode encoder for .NET Control to generate, create Barcode image in Visual Studio .NET applications. www.OnBarcode.comIdentcode Creation In Visual C#.NET Using Barcode generator for .NET Control to generate, create Identcode image in .NET applications. www.OnBarcode.comOkay, so the network is available (at least as far as your application can tell) and the server hosting your SQL Server instance is visible on the network. Next, you can query the .NET Framework to see what SQL Server instances are visible. This is a two-step process that s simplified somewhat because we re interested only in SQL Server instances (and not other services like Reporting Services or Exchange). In summary, the code shown in listing 3 performs the following steps: Encoding Code 128 Code Set C In Java Using Barcode generation for Java Control to generate, create Code 128B image in Java applications. www.OnBarcode.comDraw Code-128 In VB.NET Using Barcode generator for .NET Control to generate, create Code 128C image in .NET framework applications. www.OnBarcode.comFirst, use the ADO.NET (2.0) System.Data.Common.DbProviderFactories object s GetFactoryClasses method to harvest the .NET data providers installed on the system. This method returns a DataTable. Pick out the SqlClient data provider row and pass it to the DbProviderFactories.GetFactory method. In this case you get a DbDataSourceEnumerator object that can be inspected via the GetDataSources method to find the visible SQL Server instances. Barcode Creator In Java Using Barcode drawer for Java Control to generate, create Barcode image in Java applications. www.OnBarcode.comDraw EAN 128 In Java Using Barcode drawer for BIRT reports Control to generate, create EAN / UCC - 14 image in BIRT reports applications. www.OnBarcode.comThis is the same technique used by the Data Connection dialog box in Visual Studio and SSMS (you know, the dialog box that takes 10 seconds or so to enumerate the visible servers). This means you need to expect a similar delay before the GetFactory method completes. A code segment to perform these operations is shown in listing 3. Generate Code 39 Extended In Java Using Barcode generator for Android Control to generate, create Code 39 Full ASCII image in Android applications. www.OnBarcode.comDataMatrix Generation In None Using Barcode generator for Software Control to generate, create DataMatrix image in Software applications. www.OnBarcode.comListing 3 Capturing the list of visible SQL Server instances
Generate EAN 13 In VB.NET Using Barcode creator for .NET Control to generate, create EAN / UCC - 13 image in .NET applications. www.OnBarcode.comGenerate UCC - 12 In .NET Framework Using Barcode creation for Reporting Service Control to generate, create UPC Symbol image in Reporting Service applications. www.OnBarcode.comPrivate Sub ShowInstance(ByVal drProvider As DataRow) Try Me.Cursor = Cursors.WaitCursor
Encode Quick Response Code In .NET Using Barcode maker for Reporting Service Control to generate, create QR image in Reporting Service applications. www.OnBarcode.comCreating EAN 128 In Java Using Barcode creation for Java Control to generate, create USS-128 image in Java applications. www.OnBarcode.comGetting and staying connected or not
Drawing Barcode In Java Using Barcode generator for Android Control to generate, create Barcode image in Android applications. www.OnBarcode.comBarcode Maker In None Using Barcode drawer for Online Control to generate, create Barcode image in Online applications. www.OnBarcode.comDim factory As DbProviderFactory = _ DbProviderFactories.GetFactory(drProvider) Dim dsE As DbDataSourceEnumerator = _ factory.CreateDataSourceEnumerator() If dsE Is Nothing Then DataGridView1.DataSource = Nothing MsgBox("No instances visible for this provider(" _ & drProvider(0).ToString & ")") Else DataGridView1.DataSource = dsE.GetDataSources() End If Catch exNS As NotSupportedException MsgBox("This provider does not support data source enumeration...") Catch exCE As System.Configuration.ConfigurationException MsgBox("The " & drProvider(0).ToString & " could not be loaded.") Finally Me.Cursor = Cursors.Default End Try End Sub NOTE
This method exposes only those instances that can be referenced by the SqlClient .NET data provider. This means that only SQL Server instances are shown; Reporting Services, Analysis Services, and other related services are not included. If everything has gone well, you can see the target SQL Server instance so you know the service is being exposed by the SQL Browser. Remember that the code shown previously searches the registry for installed instances, but you still don t know if the SQL Server instance has been started or if, perhaps, a DBA has paused the instance. The code to determine the instance state is quicker and simpler than searching for visible server instances. In this case, your code calls the System.ServiceProcess.ServicesController class to test the current service status. This same class can also be used to set the service status. This means you ll be able to start, stop, or pause a specific SQL Server instance (if you have sufficient rights). The trick here is to pass the correct arguments to the ServicesController class to properly identify the SQL Server instance. When the industry transitioned from SQL Server 2000 (version 8.0) to SQL Server 2005 (version 9.0), the method of referencing instances changed. SQL Server 2000 uses the service name of MSSQLSERVER. From SQL Server 2005 on, the service name changed to MSSQL followed by the instance name (separated with a $). For example, on my web site I have an instance of SQL Server 2005 named SS2K8, which shows up in services.msc as SQL Server (SS2K8) with a service name of MSSQL$SS2K8. Unfortunately, the .NET factory classes require you to pass in the same string that appears in services.msc when asked for the service name. It can be a bit confusing. Perhaps the example in listing 4 will make this easier. For purposes of this exercise, let s assume we re working with SQL Server 2005 or later. Listing 4 illustrates a routine that starts a selected SQL Server instance on a
|
|