Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

Wednesday, March 28, 2012

Script to stop SQL server services and SQL instances.

What is the best way to write a scrip to Stop SQL Server service or SQL
Instance servies.
Thanks for the help.net stop mssqlserver
<msnews.microsoft.com> wrote in message
news:u7wBZIX8HHA.3624@.TK2MSFTNGP05.phx.gbl...
> What is the best way to write a scrip to Stop SQL Server service or SQL
> Instance servies.
> Thanks for the help.
>

Script to stop a SQL service

Is there a script that I can run to stop a particular SQL server service on
Win2003 server? I'm looking for a similar script to restart that service as
well. Thanks.NET START <service>
NET STOP <service
If you have a default instance install of SQL Server 200: "NET START
MSSQLSERVER"

Regards
----------
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland

IM: mike@.epprecht.net

MVP Program: http://www.microsoft.com/mvp

Blog: http://www.msmvps.com/epprecht/

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
> Is there a script that I can run to stop a particular SQL server service
> on Win2003 server? I'm looking for a similar script to restart that
> service as well. Thanks.|||You can use the NET STOP and NET START commands from the command-prompt to
stop/start any Windows service. For a default SQL Server instance:

NET STOP MSSQLSERVER
NET START MSSQLSERVER

For a named instance:

NET STOP MSSQL$MyInstance
NET START MSSQL$MyInstance

You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
Examples:

'stop example
Option Explicit
Dim oSQLServer
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLServer.Name = "MyServer"
oSQLServer.Stop

'start example
Option Explicit
Dim oSQLServer
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLServer.Start False, "MyServer"

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
> Is there a script that I can run to stop a particular SQL server service
> on Win2003 server? I'm looking for a similar script to restart that
> service as well. Thanks.|||Would the syntax be the same if I ran the command line script from within a
batch file?

I'm planning on running this batch file from within the BackUp Exec
software. I have two database programs that run SQL services, preventing
the backup jobs from doing a thorough job. Automatically shutting down
those SQL services will allow jobs to complete properly.

"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
> You can use the NET STOP and NET START commands from the command-prompt to
> stop/start any Windows service. For a default SQL Server instance:
> NET STOP MSSQLSERVER
> NET START MSSQLSERVER
> For a named instance:
> NET STOP MSSQL$MyInstance
> NET START MSSQL$MyInstance
> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
> Examples:
> 'stop example
> Option Explicit
> Dim oSQLServer
> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
> oSQLServer.Name = "MyServer"
> oSQLServer.Stop
> 'start example
> Option Explicit
> Dim oSQLServer
> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
> oSQLServer.Start False, "MyServer"
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>> Is there a script that I can run to stop a particular SQL server service
>> on Win2003 server? I'm looking for a similar script to restart that
>> service as well. Thanks.
>>
>>|||> Would the syntax be the same if I ran the command line script from within
> a batch file?

Yes.

> I'm planning on running this batch file from within the BackUp Exec
> software. I have two database programs that run SQL services, preventing
> the backup jobs from doing a thorough job. Automatically shutting down
> those SQL services will allow jobs to complete properly.

Rather than cold backups, consider backing up your databases to disk using
Transact-SQL BACKUP DATABASE and then archiving the disk backup files to
tape using your backup software. This allows you to perform backups while
the databases are online and uses less tape storage. Many backup vendors
also provide a specialized backup agent for SQL Server that allows you to
backup SQL Server databases online.

In any case, be sure to thoroughly test your recovery procedure.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:Y_-dncZAa9tM3lbfRVn-hQ@.comcast.com...
> Would the syntax be the same if I ran the command line script from within
> a batch file?
> I'm planning on running this batch file from within the BackUp Exec
> software. I have two database programs that run SQL services, preventing
> the backup jobs from doing a thorough job. Automatically shutting down
> those SQL services will allow jobs to complete properly.
>
> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
> news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
>> You can use the NET STOP and NET START commands from the command-prompt
>> to stop/start any Windows service. For a default SQL Server instance:
>>
>> NET STOP MSSQLSERVER
>> NET START MSSQLSERVER
>>
>> For a named instance:
>>
>> NET STOP MSSQL$MyInstance
>> NET START MSSQL$MyInstance
>>
>> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
>> Examples:
>>
>> 'stop example
>> Option Explicit
>> Dim oSQLServer
>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>> oSQLServer.Name = "MyServer"
>> oSQLServer.Stop
>>
>> 'start example
>> Option Explicit
>> Dim oSQLServer
>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>> oSQLServer.Start False, "MyServer"
>>
>> --
>> Hope this helps.
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
>> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>>> Is there a script that I can run to stop a particular SQL server service
>>> on Win2003 server? I'm looking for a similar script to restart that
>>> service as well. Thanks.
>>>
>>>
>>
>>|||Thanks, guys. I'll give it a shot.

"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:zOQye.2686$vT3.2657@.newssvr30.news.prodigy.co m...
>> Would the syntax be the same if I ran the command line script from within
>> a batch file?
> Yes.
>> I'm planning on running this batch file from within the BackUp Exec
>> software. I have two database programs that run SQL services, preventing
>> the backup jobs from doing a thorough job. Automatically shutting down
>> those SQL services will allow jobs to complete properly.
> Rather than cold backups, consider backing up your databases to disk using
> Transact-SQL BACKUP DATABASE and then archiving the disk backup files to
> tape using your backup software. This allows you to perform backups while
> the databases are online and uses less tape storage. Many backup vendors
> also provide a specialized backup agent for SQL Server that allows you to
> backup SQL Server databases online.
> In any case, be sure to thoroughly test your recovery procedure.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
> news:Y_-dncZAa9tM3lbfRVn-hQ@.comcast.com...
>> Would the syntax be the same if I ran the command line script from within
>> a batch file?
>>
>> I'm planning on running this batch file from within the BackUp Exec
>> software. I have two database programs that run SQL services, preventing
>> the backup jobs from doing a thorough job. Automatically shutting down
>> those SQL services will allow jobs to complete properly.
>>
>>
>> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
>> news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
>>> You can use the NET STOP and NET START commands from the command-prompt
>>> to stop/start any Windows service. For a default SQL Server instance:
>>>
>>> NET STOP MSSQLSERVER
>>> NET START MSSQLSERVER
>>>
>>> For a named instance:
>>>
>>> NET STOP MSSQL$MyInstance
>>> NET START MSSQL$MyInstance
>>>
>>> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
>>> Examples:
>>>
>>> 'stop example
>>> Option Explicit
>>> Dim oSQLServer
>>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>>> oSQLServer.Name = "MyServer"
>>> oSQLServer.Stop
>>>
>>> 'start example
>>> Option Explicit
>>> Dim oSQLServer
>>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>>> oSQLServer.Start False, "MyServer"
>>>
>>> --
>>> Hope this helps.
>>>
>>> Dan Guzman
>>> SQL Server MVP
>>>
>>> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
>>> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>>>> Is there a script that I can run to stop a particular SQL server
>>>> service on Win2003 server? I'm looking for a similar script to restart
>>>> that service as well. Thanks.
>>>>
>>>>
>>>
>>>
>>
>>

Wednesday, March 21, 2012

Script Task - Am I leaving any resources open?

I've got a service that waits for a file to drop and then calls a ssis package that then gets a date from the first line of the file, sets it to a variable, then imports the rest of the file using the flat file import through a data flow task.

Occasionally the script task fails with this error message:

The script threw an exception: Access to the path 'C:\path\flatfile.txt' is denied.

Here is the code of my script:

Public Sub Main()
'
' Add your code here
'
Dim vars As Variables
Dts.VariableDispenser.LockOneForRead("User::FullFilePath", vars)

Dim filepath As String = vars("FullFilePath").Value.ToString()

vars.Unlock()

Dim file As File
Dim reader As StreamReader

reader = file.OpenText(filepath)

Dim line As String
line = reader.ReadLine()

reader.Close()

'MsgBox(line.Substring(29))

Dim asofdate As String
asofdate = line.Substring(29, 5)
asofdate = asofdate + "20" + line.Substring(34)

'MsgBox(asofdate)

Dim writeVars As Variables
Dts.VariableDispenser.LockOneForWrite("User::AsOfDate", writeVars)
writeVars(0).Value = asofdate

'MsgBox("done")

writeVars.Unlock()

Dts.TaskResult = Dts.Results.Success
End Sub

Does anyone see anything that I'm not. I believe i'm closing all necessary resources and streams. Does anyone have suggestions.

Thank you very much in advance.

Is it possible that your service calls the package multiple times simultaneously, or that the package could be executed before the drop is completed? The access violation in either of those cases would be due to the file still being locked by something else (e.g. the process writing the file, or the first package processing the file).

If neither are the case, then you could try a small re-write to see if it helps:

Replace:

Dim file As File
Dim reader As StreamReader

reader = file.OpenText(filepath)

Dim line As String
line = reader.ReadLine()

reader.Close()

With:

Dim line As String

Using reader as new StreamReader(filepath)

line = reader.Readline()

reader.Close()

End Using

HTH,

Patrik

|||Thanks for your response.

After banging my head against the table for a day i realized that the reason I was having issues is because the package in question was running as a service. The service was running under a particular user or usergroup. This usergroup was not one that had access to the files being run through my package, and therefore the package had its access deined by the OS.

In the interest of helping others, I'll leave this post up, even though it should have been one of the first things I tried.

Tuesday, March 20, 2012

Script restart service?

Try asking them here. x-posted to: public.sqlserver.server
[url]http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sqlserver.server& cat=en_US_671e06d0-f20d-4bb3-9c6a-42c825ddb1dc&lang=en&cr=US[/url]

Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Mike Risoli" wrote:
> Hello all,
> I developed a script that was launched using psexec to read through the
> “Add/Remove” programs. Because a majority of our servers are Windows 2003,
> I
> had to enable the “WMI Windows Installer Provider” via the script. I did
> this
> as follows:
> sysocmgr /i:%windir%\inf\sysoc.inf /r /q /u:"answer.txt"
> The answer file is:
> [Components]
> WbemMSI=on
> On about half of our SQL Server boxes, the SQL Service was stopped.
> When I reviewed these servers, I noticed all the failed boxes were
> running:
> Windows 2003 SP1
> SQL 2000
> The servers running SQL 2005, worked without issue.
> The difference between this list is .Net related. It seems that all the
> .Net
> 2.0 servers (whether installed via R2 or SQL 2005) are ok, but the .Net
> 1.1
> and higher (Windows 2003 SP1 or SQL 2000) had restarted services.
> My questions is:
> Why would enabling the “WMI Windows Installer Provider” cause the SQL
> Service to stop/restart?
> --
> Thanks,
> Mike
>
Thanks Dave. Based on the issue, I wasn't sure where to post this.
Any help by the group would be greatly appreciated.
Thanks,
Mike
"Dave Patrick" wrote:

> Try asking them here. x-posted to: public.sqlserver.server
> [url]http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sqlserver.server& cat=en_US_671e06d0-f20d-4bb3-9c6a-42c825ddb1dc&lang=en&cr=US[/url]
>
> --
> Regards,
> Dave Patrick ...Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
> http://www.microsoft.com/protect
> "Mike Risoli" wrote:
>
|||Thanks Dave. Based on the issue, I wasn't sure where to post this.
Any help by the group would be greatly appreciated.
Thanks,
Mike
"Dave Patrick" wrote:

> Try asking them here. x-posted to: public.sqlserver.server
> [url]http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sqlserver.server& cat=en_US_671e06d0-f20d-4bb3-9c6a-42c825ddb1dc&lang=en&cr=US[/url]
>
> --
> Regards,
> Dave Patrick ...Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
> http://www.microsoft.com/protect
> "Mike Risoli" wrote:
>

Monday, March 12, 2012

script for generating service user account?

Hi,
Is there a script available to create the sql server service account and set
the file system and registry permissions correctly? I would like to run my
server with minimum access rights and I would like to save some time if
someone has done a nice script for creating the account and/or setting the
permissions in a way that it can easily be reused.
Svenhave a look at this
http://support.microsoft.com/kb/283811/en-us
this details what you need to script.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Matzen" <Matzen@.discussions.microsoft.com> wrote in message
news:AA0493D1-A1F6-43F3-9D34-4A590FD410F8@.microsoft.com...
> Hi,
> Is there a script available to create the sql server service account and
> set
> the file system and registry permissions correctly? I would like to run my
> server with minimum access rights and I would like to save some time if
> someone has done a nice script for creating the account and/or setting the
> permissions in a way that it can easily be reused.
> Sven

script for generating service user account?

Hi,
Is there a script available to create the sql server service account and set
the file system and registry permissions correctly? I would like to run my
server with minimum access rights and I would like to save some time if
someone has done a nice script for creating the account and/or setting the
permissions in a way that it can easily be reused.
Svenhave a look at this
http://support.microsoft.com/kb/283811/en-us
this details what you need to script.
--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Matzen" <Matzen@.discussions.microsoft.com> wrote in message
news:AA0493D1-A1F6-43F3-9D34-4A590FD410F8@.microsoft.com...
> Hi,
> Is there a script available to create the sql server service account and
> set
> the file system and registry permissions correctly? I would like to run my
> server with minimum access rights and I would like to save some time if
> someone has done a nice script for creating the account and/or setting the
> permissions in a way that it can easily be reused.
> Sven