Showing posts with label run. Show all posts
Showing posts with label run. Show all posts

Friday, March 23, 2012

How to get the full contents of the text column in syscomments

HI All ,

I need to extract the full text of a procedure from the syscomments table. When I run the query in query Analyzer and do a 'save as' to a textfile, I get only part of the text.

Appreciate any response on this.

Thanks

Two things, the first one is that the definition, column [text], is nvarchar(4000), so the output in QA should be a least 4000 characters. You can set it changing "Tools - Options... - Results - Maximum characters per column:" to 8192 (8k).

Second, if the definition, for example of the stored procedure, is greater than 4000, then you will have to select from multiple rows. The value of the column [colid] give you the sequence.

AMB

|||Thanks a lot ,it worked.sql

Monday, March 19, 2012

how to get sql procedure parameters count and their type?

Hi All,
i am using DBLib and VC++. i want to know the number of parameters
of a procedure at run time. is it posible if yes then how can i do this.
thanks.Use ADO's OpenSchema method with the schema ID: adProcedureParameters|||is there another way of getting parameter count other than ADO.
actually we dont use ADO. some winodws api etc.

thanks for reply.

omar|||Check out INFORMATION_SCHEMA.ROUTINE_COLUMNS

How to get service accounts for 150 servers

Hi Everyone.

I have 150 SQL servers (2000 MSDE). They all run using various domain accounts as their service logins. Is there an automated way to find out those service logins? Maybe a query I could run on each server?

I really do not want to go to each of those 150 servers and look at their properties manualy! :S

Any help would be greatly appreciated! Thank you.Something around the master.dbo.sysusers and/or master.dbo.syslogins
table(s) ?|||I think that you want the startname value from this (http://www.microsoft.com/technet/scriptcenter/scripts/os/services/ossvvb08.mspx) script.

-PatP|||I think that you want the startname value from this (http://www.microsoft.com/technet/scriptcenter/scripts/os/services/ossvvb08.mspx) script.

-PatP

Yeah, I would think that WMI would be your best bet. Dump the list of servers into a text file (or XML). Open that file using the File system object and spin through (using oFile.ReadLine). Then feed the string value (the computer name) into a function that returns the name of of the service account you are looking for. Dump that into a separate text file (or a database).

Regards,

hmscott|||Thank you everyone for responding. I got an answer at experts-exchange. The following query will return the service account:

declare @.rc int,
@.dir nvarchar(4000)
exec @.rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'System\CurrentControlSet\S ervices\MSSQLServer\',N'ObjectName', @.dir output, 'no_output'
select @.dir

I've modified it put the result in the central table and then ran it through a SQL loop. Worked perfectly! :D

WMI would have worked as well, but this solution took just 10 min to implement.

P.S. Had no idea that something like xp_instance_regread existed. Is too much to hope that sql server 2005 will have better documentation? :-)|||That Transact-SQL code will work nicely as long as you only need the default instance of SQL 2000.

-PatP|||That Transact-SQL code will work nicely as long as you only need the default instance of SQL 2000.

-PatP

Good point, Pat. For named instances the command will need to be modified:

declare @.rc int,
@.dir nvarchar(4000)
exec @.rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'System\CurrentControlSet\S ervices\MSSQL$Your_Instance_Name\',N'ObjectName', @.dir output, 'no_output'
select @.dir

Monday, March 12, 2012

How to get running stored procs

Is there a script I can run that identifies the stored procedures that
are running NOW?
Regards
On Jun 7, 4:24 am, Frank Rizzo <n...@.none.com> wrote:
> Is there a script I can run that identifies the stored procedures that
> are running NOW?
> Regards
sql profiler show you the current proceses.
|||Hello Frank,
You may need to use the SQL Profiler to track the running stored procedure.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
|||On Jun 7, 3:24 am, Frank Rizzo <n...@.none.com> wrote:
> Is there a script I can run that identifies the stored procedures that
> are running NOW?
> Regards
Check Erland's website
http://www.sommarskog.se/sqlutil/aba_lockinfo.html
you can use this
|||Execute the profiler and in event selection select "Stored procedures and
select the check box "RPC Completed". After specific time save the contents
into a table and filter it out.
Thanks
Hari
"Frank Rizzo" <none@.none.com> wrote in message
news:OpVP9lIqHHA.3888@.TK2MSFTNGP05.phx.gbl...
> Is there a script I can run that identifies the stored procedures that are
> running NOW?
> Regards
|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

How to get running stored procs

Is there a script I can run that identifies the stored procedures that
are running NOW?
RegardsOn Jun 7, 4:24 am, Frank Rizzo <n...@.none.com> wrote:
> Is there a script I can run that identifies the stored procedures that
> are running NOW?
> Regards
sql profiler show you the current proceses.|||Hello Frank,
You may need to use the SQL Profiler to track the running stored procedure.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||On Jun 7, 3:24 am, Frank Rizzo <n...@.none.com> wrote:
> Is there a script I can run that identifies the stored procedures that
> are running NOW?
> Regards
Check Erland's website
http://www.sommarskog.se/sqlutil/aba_lockinfo.html
you can use this|||Execute the profiler and in event selection select "Stored procedures and
select the check box "RPC Completed". After specific time save the contents
into a table and filter it out.
Thanks
Hari
"Frank Rizzo" <none@.none.com> wrote in message
news:OpVP9lIqHHA.3888@.TK2MSFTNGP05.phx.gbl...
> Is there a script I can run that identifies the stored procedures that are
> running NOW?
> Regards|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.

How to get running stored procs

Is there a script I can run that identifies the stored procedures that
are running NOW?
RegardsOn Jun 7, 4:24 am, Frank Rizzo <n...@.none.com> wrote:
> Is there a script I can run that identifies the stored procedures that
> are running NOW?
> Regards
sql profiler show you the current proceses.|||Hello Frank,
You may need to use the SQL Profiler to track the running stored procedure.
Sincerely,
Wei Lu
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.|||On Jun 7, 3:24 am, Frank Rizzo <n...@.none.com> wrote:
> Is there a script I can run that identifies the stored procedures that
> are running NOW?
> Regards
Check Erland's website
http://www.sommarskog.se/sqlutil/aba_lockinfo.html
you can use this|||Execute the profiler and in event selection select "Stored procedures and
select the check box "RPC Completed". After specific time save the contents
into a table and filter it out.
Thanks
Hari
"Frank Rizzo" <none@.none.com> wrote in message
news:OpVP9lIqHHA.3888@.TK2MSFTNGP05.phx.gbl...
> Is there a script I can run that identifies the stored procedures that are
> running NOW?
> Regards|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.

Friday, February 24, 2012

How to get job history/error info. from a custom .exe being run by the job?

How to get job history/error info. from a custom .exe being run by the job?

We're using SQL Server 2005 and SQL Server Agent to run some jobs. These jobs execute a custom .exe program (written in C#).

What we're wondering is, is there any way to send status/history information from the custom .exe back to the job that kicked it off?

We're trying to provide execution info. to show if the job succeeded or if some error occurred in the .exe (thus the job didn't complete successfully).

Thanks!

Have the custom app logs to a file then when the job exits, load the logs/histories into a sql table.

Sunday, February 19, 2012

How to get DMO to schedule a Stored Procedure as a Job?

I have what is a simple task. Using C# I want to schedule a SQL Server
Stored Procedure to run at a specified date & time.
I've seen plenty of examples of running SQL code like this but none about
running a stored procedure. The closest I've come is this:
http://msdn.microsoft.com/library/d... />
j_9uwk.asp
Can anyone point me to an example that would help me accomplish what I'm
trying to do?
Robert W.
Vancouver, BC
www.mwtech.comHi,
Below is an example I knocked together of calling SQLDMO from C#. It's
by no means perfect but it should be enough to get you started. You'll
probably need to clean up some formatting as the action of posting
probably ruined all of it. Just a few things to note:
1) You will need to reference the appropriate DLL for SQLDMO in your C#
project
2) You can add a "using SQLDMO;" statement to your code if you don't
want to prefix SQLDMO objects with "SQLDMO".
Hope this helps a bit
========================================
=======
public static void createNewJob()
{
/* Variable declaration */
SQLDMO.SQLServer theServer; //Object representing the connection to a
DB server
SQLDMO.Job jobToBeCreated; //Object representing the job to be created
on the server
SQLDMO.JobSchedule scheduleForCreatedJob; //Schedule of job to create
SQLDMO.JobStep stepForCreatedJob; //What the job will do
/*
* Process done in this order:
*
* 1) Connect to the database server
* 2) Create a Job object representing the job we want to add
* 3) Create a JobStep object representing what we want this job to do
(e.g. execute some T-SQL)
* 4) Create a JobSchedule object representing when we want this job
executed
* 5) Add the JobStep and JobSchedule objects to the Job object
* 6) Add the Job object to the jobs currently defined on the server
*
* NOTE: We need to connect to the server first because some methods
used to define a job require that
* we be connected to a database server
*/
theServer = new SQLDMO.SQLServerClass();
theServer.LoginSecure = false; //Use SQL Server Authentication
theServer.Login = "sa"; //Change to whatever SQL Server login you want
theServer.Password = ""; //Change to the password associated with the
user set previously
theServer.Connect("N-0U9LWEXW762ZV\\NATHAN", theServer.Login,
theServer.Password);
jobToBeCreated = new SQLDMO.JobClass();
jobToBeCreated.Name = "Example Job";
theServer.JobServer.Jobs.Add(jobToBeCreated);
stepForCreatedJob = new SQLDMO.JobStepClass();
stepForCreatedJob.Name = "Stored procedure execution";
stepForCreatedJob.StepID = 1;
stepForCreatedJob.Command = "exec sp_monitor"; //Change stored proc as
appropriate
scheduleForCreatedJob = new SQLDMO.JobScheduleClass();
scheduleForCreatedJob.Name = "Example schedule";
scheduleForCreatedJob.Enabled = true;
jobToBeCreated.JobSchedules.Add(scheduleForCreatedJob);
/*
* Configure a "one-shot" (i.e. the job will execute once {and only
once})
*/
scheduleForCreatedJob.Schedule.ActiveStartDate = 20060513; //Equivalent
to 05/13/2006 in dd/mm/yyyy
scheduleForCreatedJob.Schedule.ActiveStartTimeOfDay = 233000;
//Equivalent to hh:mm:ss
scheduleForCreatedJob.Schedule.ActiveEndDate = 20070513; //Value
irrelevant as the job is "one-shot"
scheduleForCreatedJob.Schedule.ActiveEndTimeOfDay = 230000; //Value
irrelevant as the job is "one-shot"
scheduleForCreatedJob.Schedule.FrequencyType =
SQLDMO.SQLDMO_FREQUENCY_TYPE.SQLDMOFreq_OneTime; //One shot
jobToBeCreated.JobSteps.Add(stepForCreatedJob);
jobToBeCreated.StartStepID = 1; //Step ID for the step we defined
previously
jobToBeCreated.ApplyToTargetServer("(local)"); //Job runs on server
running the SQL Server Agent
theServer.DisConnect();
}|||Nate,
Thank you so much! I will review your code and see if I can adapt it my
specific needs!!
Robert W.
Vancouver, BC
www.mwtech.com
"nate.vu@.gmail.com" wrote:

> Hi,
> Below is an example I knocked together of calling SQLDMO from C#. It's
> by no means perfect but it should be enough to get you started. You'll
> probably need to clean up some formatting as the action of posting
> probably ruined all of it. Just a few things to note:
> 1) You will need to reference the appropriate DLL for SQLDMO in your C#
> project
> 2) You can add a "using SQLDMO;" statement to your code if you don't
> want to prefix SQLDMO objects with "SQLDMO".
> Hope this helps a bit
> ========================================
=======
> public static void createNewJob()
> {
> /* Variable declaration */
> SQLDMO.SQLServer theServer; //Object representing the connection to a
> DB server
> SQLDMO.Job jobToBeCreated; //Object representing the job to be created
> on the server
> SQLDMO.JobSchedule scheduleForCreatedJob; //Schedule of job to create
> SQLDMO.JobStep stepForCreatedJob; //What the job will do
> /*
> * Process done in this order:
> *
> * 1) Connect to the database server
> * 2) Create a Job object representing the job we want to add
> * 3) Create a JobStep object representing what we want this job to do
> (e.g. execute some T-SQL)
> * 4) Create a JobSchedule object representing when we want this job
> executed
> * 5) Add the JobStep and JobSchedule objects to the Job object
> * 6) Add the Job object to the jobs currently defined on the server
> *
> * NOTE: We need to connect to the server first because some methods
> used to define a job require that
> * we be connected to a database server
> */
> theServer = new SQLDMO.SQLServerClass();
> theServer.LoginSecure = false; //Use SQL Server Authentication
> theServer.Login = "sa"; //Change to whatever SQL Server login you want
> theServer.Password = ""; //Change to the password associated with the
> user set previously
> theServer.Connect("N-0U9LWEXW762ZV\\NATHAN", theServer.Login,
> theServer.Password);
> jobToBeCreated = new SQLDMO.JobClass();
> jobToBeCreated.Name = "Example Job";
> theServer.JobServer.Jobs.Add(jobToBeCreated);
> stepForCreatedJob = new SQLDMO.JobStepClass();
> stepForCreatedJob.Name = "Stored procedure execution";
> stepForCreatedJob.StepID = 1;
> stepForCreatedJob.Command = "exec sp_monitor"; //Change stored proc as
> appropriate
> scheduleForCreatedJob = new SQLDMO.JobScheduleClass();
> scheduleForCreatedJob.Name = "Example schedule";
> scheduleForCreatedJob.Enabled = true;
> jobToBeCreated.JobSchedules.Add(scheduleForCreatedJob);
> /*
> * Configure a "one-shot" (i.e. the job will execute once {and only
> once})
> */
> scheduleForCreatedJob.Schedule.ActiveStartDate = 20060513; //Equivalent
> to 05/13/2006 in dd/mm/yyyy
> scheduleForCreatedJob.Schedule.ActiveStartTimeOfDay = 233000;
> //Equivalent to hh:mm:ss
> scheduleForCreatedJob.Schedule.ActiveEndDate = 20070513; //Value
> irrelevant as the job is "one-shot"
> scheduleForCreatedJob.Schedule.ActiveEndTimeOfDay = 230000; //Value
> irrelevant as the job is "one-shot"
> scheduleForCreatedJob.Schedule.FrequencyType =
> SQLDMO.SQLDMO_FREQUENCY_TYPE.SQLDMOFreq_OneTime; //One shot
> jobToBeCreated.JobSteps.Add(stepForCreatedJob);
> jobToBeCreated.StartStepID = 1; //Step ID for the step we defined
> previously
> jobToBeCreated.ApplyToTargetServer("(local)"); //Job runs on server
> running the SQL Server Agent
> theServer.DisConnect();
> }
>