Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Monday, March 26, 2012

proper way to set parameters programatically?

What is the proper way to set a parameter collection's values in code? (C#
or VB.NET) should you get the parameter list using getReportParameters from
the SOAP web service then setting the items in the returned collection then
passing the collection back through setreportparameters..... or can you
just pass a list of programatically created values and names though the
setReportParaemters with out having to get the initial list (say if you
already know the parameters required) thanks!See the examples using parameters here:
http://msdn2.microsoft.com/en-us/library/aa258532(sql.80).aspx
This applies to the render method, which I'm not sure if you'll use or
not, but I think this should give you an idea of what to do.
Smokey Grindle wrote:
> What is the proper way to set a parameter collection's values in code? (C#
> or VB.NET) should you get the parameter list using getReportParameters from
> the SOAP web service then setting the items in the returned collection then
> passing the collection back through setreportparameters..... or can you
> just pass a list of programatically created values and names though the
> setReportParaemters with out having to get the initial list (say if you
> already know the parameters required) thanks!

Friday, March 23, 2012

Prompting connection str to access SQL server

Hi ,
my connection string is as per follows but how can i made it such that i
need not hard code the useid & pwd w/o having to create a user interface ?
tks & rdgs
Can you please send the connection string
best Regards,
Chandra
http://chanduas.blogspot.com/
"maxzsim" wrote:

> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgs
|||As far as I understand - you must use trusted connection option and depend
on account that your application work with.
Bojidar Alexandrov
"maxzsim" <maxzsim@.discussions.microsoft.com> wrote in message
news:DD415C15-32D4-43DC-B9AC-5C44D08DC738@.microsoft.com...
> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgs
|||That depends just on your application you code, there are serveral ways for
doing this:
Storing the password in a external storage (evtl. with encryption)
-registry
-xml file
-active directory
...
Using Windows Authentification:
http://msdn.microsoft.com/library/de...urity_47u6.asp
Using a DSN to connect with, (Has already a GUI ;-) )
But all that depends ont eh app you are coding the enviroment and so on..
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
"maxzsim" <maxzsim@.discussions.microsoft.com> schrieb im Newsbeitrag
news:DD415C15-32D4-43DC-B9AC-5C44D08DC738@.microsoft.com...
> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgs

Prompting connection str to access SQL server

Hi ,
my connection string is as per follows but how can i made it such that i
need not hard code the useid & pwd w/o having to create a user interface ?
tks & rdgsCan you please send the connection string
--
best Regards,
Chandra
http://chanduas.blogspot.com/
---
"maxzsim" wrote:

> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgs|||As far as I understand - you must use trusted connection option and depend
on account that your application work with.
Bojidar Alexandrov
"maxzsim" <maxzsim@.discussions.microsoft.com> wrote in message
news:DD415C15-32D4-43DC-B9AC-5C44D08DC738@.microsoft.com...
> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgs|||That depends just on your application you code, there are serveral ways for
doing this:
Storing the password in a external storage (evtl. with encryption)
-registry
-xml file
-active directory
..
Using Windows Authentification:
http://msdn.microsoft.com/library/d...>
ity_47u6.asp
Using a DSN to connect with, (Has already a GUI ;-) )
But all that depends ont eh app you are coding the enviroment and so on..
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"maxzsim" <maxzsim@.discussions.microsoft.com> schrieb im Newsbeitrag
news:DD415C15-32D4-43DC-B9AC-5C44D08DC738@.microsoft.com...
> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgs

Prompting connection str to access SQL server

Hi ,
my connection string is as per follows but how can i made it such that i
need not hard code the useid & pwd w/o having to create a user interface ?
tks & rdgsCan you please send the connection string
--
best Regards,
Chandra
http://chanduas.blogspot.com/
---
"maxzsim" wrote:
> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgs|||As far as I understand - you must use trusted connection option and depend
on account that your application work with.
Bojidar Alexandrov
"maxzsim" <maxzsim@.discussions.microsoft.com> wrote in message
news:DD415C15-32D4-43DC-B9AC-5C44D08DC738@.microsoft.com...
> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgs|||That depends just on your application you code, there are serveral ways for
doing this:
Storing the password in a external storage (evtl. with encryption)
-registry
-xml file
-active directory
...
Using Windows Authentification:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_security_47u6.asp
Using a DSN to connect with, (Has already a GUI ;-) )
But all that depends ont eh app you are coding the enviroment and so on..
HTH, Jens Suessmeyer.
--
http://www.sqlserver2005.de
--
"maxzsim" <maxzsim@.discussions.microsoft.com> schrieb im Newsbeitrag
news:DD415C15-32D4-43DC-B9AC-5C44D08DC738@.microsoft.com...
> Hi ,
> my connection string is as per follows but how can i made it such that i
> need not hard code the useid & pwd w/o having to create a user interface ?
> tks & rdgssql

Prompt for value

What is the sql code to prompt for a value?
Can I do this in query analyzer or do I have to send the value from some other application?the query analyser cannot prompt the user for a value.|||Prompting for values is the responsibility of the application interface. Query Analyzer is a tool, but it is by no means an application interface.

Wednesday, March 21, 2012

Project_Central

We created Project_Central Database using this code:
osql -U dbadmin -i Crttable.sql
osql -U dbadmin -P glance -d Project_CentralDB -i Insdefsq.sql
osql -U dbadmin -P glance -d Project_CentralDB -i Insdefsi.sql
Even though the Project_Central Database does not show single user in the
server itself. It displays this error. How can we turn the single user mode
off. Please help!!
*****************
Logon failed.
The server is currently in single-user mode.
See your Microsoft Project Central administrator to return the server to
normal mode.
Return to logon.
*******************
--
ArturoCould it be that the data server itself is in single user mode? The data
server can be placed in single user mode via the -m start up flag. Check your
start-up parameters and see if the -m flag is one of them. If so, remove the
flag and restart the data server.
"Arturo" wrote:
> We created Project_Central Database using this code:
> osql -U dbadmin -i Crttable.sql
> osql -U dbadmin -P glance -d Project_CentralDB -i Insdefsq.sql
> osql -U dbadmin -P glance -d Project_CentralDB -i Insdefsi.sql
> Even though the Project_Central Database does not show single user in the
> server itself. It displays this error. How can we turn the single user mode
> off. Please help!!
> *****************
> Logon failed.
> The server is currently in single-user mode.
> See your Microsoft Project Central administrator to return the server to
> normal mode.
> Return to logon.
> *******************
> --
> Arturosql

Tuesday, March 20, 2012

PROGRAMTICALLY ACCESS SQLDATASOURCE !

I am trying to acces an SQLDatasource in the code page, I have the following code but get the error as below, any one help please

The SQLDataSource returns 1 value named [ShippingRegion], I think that has somethjing to do with it ??!!

dsShippingRegion.Select(DataSourceSelectArguments.Empty)

Dim myReaderAs Data.IDataReader =CType(dsShippingRegion.Select(DataSourceSelectArguments.Empty), Data.IDataReader)
If myReader.ReadThen
If Convert.IsDBNull(myReader("ShippingRegion"))Then
Beep()
Else
Beep()
EndIf
EndIf

System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'System.Data.DataView' to type 'System.Data.IDataReader'."
Source="App_Web_rd5quiy1"
StackTrace:
at admin_administer_shop_productaddnew.Page_Load(Object sender, EventArgs e) in E:\Web Development\WebSites\AJAX_sirs2hers\admin\administer_shop\productaddnew.aspx.vb:line 25
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

dsShippingRegion.Select(DataSourceSelectArguments.Empty)

In the SqlDataSource markup, set DataSourceMode="DataReader". If the DataSourceMode is DataSet (or is not set, since DataSet is the default), a DataView object is returned from Select, which is what you're seeing. If the DataSourceMode is DataReader, an IDataReader object is returned. Seehttp://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.select.aspx for more details.

Hope that helps.

Aaron

|||

Aaron

this is the code for adding a product, what and where would i place to retrieve the returned value from the SPROC, insert is marked at the bottom with HERE IS THE INSERT

Thanks for the help, changed datasourcemode as above

Steve

ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

If Trim(FCKeditor1.Value) =""Then

Dim AlertMSG ="Please enter product description"

ShrekGlobal.GlobalFunctions.CreateMessageAlert(Me, AlertMSG,"strKey1")

ExitSub

EndIf

Dim UploadImageAsBoolean =True

dsProduct.InsertParameters.Clear()

Dim ShopIDAsNew ControlParameter("ShopID","hfShopID","Value")

dsProduct.InsertParameters.Add(ShopID)

Dim CategoryIDAsNew ControlParameter("CategoryID","ddlCategories","SelectedValue")

dsProduct.InsertParameters.Add(CategoryID)

Dim ModelNumberAsNew ControlParameter("ModelNumber","txtModelNumber","Text")

dsProduct.InsertParameters.Add(ModelNumber)

Dim ModelNameAsNew ControlParameter("ModelName","txtModelName","Text")

dsProduct.InsertParameters.Add(ModelName)

Dim UnitCostAsNew ControlParameter("UnitCost","txtUnitCost","Text")

dsProduct.InsertParameters.Add(UnitCost)

Dim StockAsNew ControlParameter("Stock","txtStock","Text")

dsProduct.InsertParameters.Add(Stock)

Dim ProductDescriptionAsNew ControlParameter("ProductDescription","FCKeditor1","Value")

dsProduct.InsertParameters.Add(ProductDescription)

Dim ImageFilenameAsString

If ddlMainImage.SelectedIndex = 0Then

ImageFilename =""

Else

ImageFilename =String.Format("{0}.jpg", ddlMainImage.SelectedValue)

EndIf

dsProduct.InsertParameters.Add("ProductImage", ImageFilename)Dim ShippingIDUK1AsNew ControlParameter("ShippingID1","ddlUKShipping1","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDUK1)

Dim ShippingAmountUK1AsNew ControlParameter("ShippingAmount1","txtUKShipping1","Text")

dsProduct.InsertParameters.Add(ShippingAmountUK1)

Dim ShippingIDUK2AsNew ControlParameter("ShippingID2","ddlUKShipping2","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDUK2)

Dim ShippingAmountUK2AsNew ControlParameter("ShippingAmount2","txtUKShipping2","Text")

dsProduct.InsertParameters.Add(ShippingAmountUK2)

Dim ShippingIDUK3AsNew ControlParameter("ShippingID3","ddlUKShipping3","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDUK3)

Dim ShippingAmountUK3AsNew ControlParameter("ShippingAmount3","txtUKShipping3","Text")

dsProduct.InsertParameters.Add(ShippingAmountUK3)

Dim ShippingIDUK4AsNew ControlParameter("ShippingID4","ddlUKShipping4","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDUK4)

Dim ShippingAmountUK4AsNew ControlParameter("ShippingAmount4","txtUKShipping4","Text")

dsProduct.InsertParameters.Add(ShippingAmountUK4)

Dim ShippingIDUK5AsNew ControlParameter("ShippingID5","ddlUKShipping5","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDUK5)

Dim ShippingAmountUK5AsNew ControlParameter("ShippingAmount5","txtUKShipping5","Text")

dsProduct.InsertParameters.Add(ShippingAmountUK5)

Dim ShippingIDInt1AsNew ControlParameter("ShippingID6","ddlIntShipping1","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDInt1)

Dim ShippingAmountInt1AsNew ControlParameter("ShippingAmount6","txtIntShipping1","Text")

dsProduct.InsertParameters.Add(ShippingAmountInt1)

Dim ShippingIDInt2AsNew ControlParameter("ShippingID7","ddlIntShipping2","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDInt2)

Dim ShippingAmountInt2AsNew ControlParameter("ShippingAmount7","txtIntShipping2","Text")

dsProduct.InsertParameters.Add(ShippingAmountInt2)

Dim ShippingIDInt3AsNew ControlParameter("ShippingID8","ddlIntShipping3","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDInt3)

Dim ShippingAmountInt3AsNew ControlParameter("ShippingAmount8","txtIntShipping3","Text")

dsProduct.InsertParameters.Add(ShippingAmountInt3)

Dim ShippingIDInt4AsNew ControlParameter("ShippingID9","ddlIntShipping4","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDInt4)

Dim ShippingAmountInt4AsNew ControlParameter("ShippingAmount9","txtIntShipping4","Text")

dsProduct.InsertParameters.Add(ShippingAmountInt4)

Dim ShippingIDInt5AsNew ControlParameter("ShippingID10","ddlIntShipping5","SelectedValue")

dsProduct.InsertParameters.Add(ShippingIDInt5)

Dim ShippingAmountInt5AsNew ControlParameter("ShippingAmount10","txtIntShipping5","Text")

dsProduct.InsertParameters.Add(ShippingAmountInt5)

'Dim ProductImage As New ControlParameter("ProductImage", "siProductImage", "NewFileName")

'dsProduct.InsertParameters.Add(ProductImage)

Try

dsProduct.Insert() HERE IS THE INSERT

Dim xAsInteger

For x = 1To 8

'Dim SaveDirectory As String = String.Format("{0}\", Server.MapPath(TemporarySaveDirectory), x)

MsgBox(ddlCategories.SelectedValue)

Dim ProductIDAsInteger = 1

Dim SaveDirectoryAsString =String.Format("~\shopping_mall\images\shops\{0}\{1}\{2}\", Session("ShopID"), ddlCategories.SelectedValue, ProductID)

If ShrekGlobal.GlobalFunctions.FileMove(String.Format("{0}.jpg", x), Server.MapPath(TemporarySaveDirectory), Server.MapPath(SaveDirectory))Then

Beep()

Else

Beep()

EndIf

Next

'siProductImage.TemporarySaveDirectory = String.Format("~\shopping_mall\images\shops\{0}\{1}", hfShopID.Value, ddlCategories.SelectedValue)

'siProductImage.Upload()

ClearPage()

Catch exAs Exception

'UploadImage = False

DeleteImage(0)

MsgBox(String.Format("{0} ~ {1}","Error", ex.Message.ToString()))

'_lblInfo1.Text = sb.ToString

' Consider customizing the message for the EmailNotSentPanel in the ShowAds page.

'Beep()

'_lblInfo1.Text = Now + " :: " + sb.ToString

EndTry

'If UploadImage Then

'Dim TemporarySaveDirectory As String

'aveDirectory =

'End If

EndSub

|||

Try this article:http://aspnet.4guysfromrolla.com/articles/050207-1.aspx

Hope that helps.

Aaron

Monday, March 12, 2012

Programming a Dashboard using SQL

Hi

Is there anywhere to locate information or code for programming a Dashboard using SQL? I would like to automate verification of several processes. Currently this is done via emails but I think a Dashboard is more efficient.

tomoPlease take a look at this thread and come back if that does not help.

programmaticaly connecting and accessing a database

I have not been able to find a code example anywhere. Someone please post the code to do this. I would be forever grateful.

I would like the code to be in C#. I want to connect to a database and then select all from a table.

thanks

Forever is a very long time my new friend.

(you need to list all the fields yourself. in my example, I just have one field. You can also leave out the WHERE clause and you will get all records).

try
{
SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CodeCampSV06"].ConnectionString);
sqlConnection.Open();

string sqlSelect = "select VistaSlotsId FROM attendees WHERE Username = @.Username";
SqlCommand sqlCommand = new SqlCommand(sqlSelect, sqlConnection);
sqlCommand.Parameters.Add("@.Username", SqlDbType.VarChar).Value = username;
vistaIdStatus = (int)sqlCommand.ExecuteScalar();

sqlConnection.Close();
sqlConnection.Dispose();

}
catch (Exception ee)
{
throw new ApplicationException(ee.ToString());
}

|||Does this code work with asp.net 2.0? sorry i forgot to mention that.|||yes it works with asp.net 2.0. That is what I am using|||

ok thanks for all the help. However i am having trouble trying to figure out what "CodeCampSV06" is. Is it the name of the DB? if so, it is not working for me.

thanks

|||

Its the name of the connectionString in the application's web.config file.

bullpit

|||

Have a look at this:

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx

good luck...

bullpit

|||

I have now used the correct string for webconfig.

But Now i keep getting this error

Error 2 The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?) C:\mine\MyProjects\Work4Tips\insert.aspx 19 9 C:\...\Work4Tips\
c

how do I solve this? The page i am trying to get this to run in is using masterpages. I am placing the code between the server tags and in these tags between a clickon method. Do I have to use a directive, if so what is it?

thanks for all your help... I am just so lost right now.

|||

Add this to your using directives list at the top of your aspx.cs file:

using

System.Data.SqlClient;

using

System.Data;

bullpit

|||

what if I am using inline code and not code behind?

does not work anywhere I place it.

|||

You can use this with your page directives at the top of the aspx page.

<%@. Import Namespace="System.Data" %>

bullpit

|||

You can also use a fully qualified statement like this:

System.Data.SqlClient.SqlConnection =new System.Data.SqlClient.SqlConnection(...)

bullpit|||

Correction to last post:

System.Data.SqlClient.SqlConnection sqlConnection =new System.Data.SqlClient.SqlConnection

Friday, March 9, 2012

Programmatically get ScriptTask source code

Hi am trying without luck to load a package which contains a ScriptTask and read the source code of that task.

I can load the package and get the ScriptTask no problem.
However i am not sure how to get the source code.
I know i have to use the ScriptTaskCodeProvider and i assume the GetSourceCode() method.

This is what i have so far

ScriptTask scriptTask = taskHost.InnerObject as ScriptTask;
ScriptTaskCodeProvider codeProvider = new ScriptTaskCodeProvider();
codeProvider.LoadFromTask(scriptTask);
string sourceCode = codeProvider.GetSourceCode(scriptTask.VsaProjectName);

Any assistance greatly appreciated.

Cheers
Richard.

Application application = new Application();

Package package = application.LoadPackage(@."C:\Yukon\ISPlaying\ISPlaying\Package14.dtsx", null);

TaskHost taskHost = package.Executables[0] as TaskHost;

ScriptTask scriptTask = taskHost.InnerObject as ScriptTask;

ScriptTaskCodeProvider codeProvider = new ScriptTaskCodeProvider();

codeProvider.LoadFromTask(scriptTask);

string script = codeProvider.GetSourceCode(String.Format("dts://Scripts/{0}/ScriptMain.vsaitem", scriptTask.VsaProjectName));

Programmatically determine Startup Account

I have over 60 servers and am looking for some code that will allow me to
query for the Startup Account user ('system' or some domain account). Where
is this information stored?
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)
There are many programming interfaces to that property. I typically like to
use command line utility to grab the information from each server, and parse
the text for the service account info. For instance, you can use NT resource
kit tool sc.exe for this purpose.
Linchi
"Blue Sky" wrote:

> I have over 60 servers and am looking for some code that will allow me to
> query for the Startup Account user ('system' or some domain account). Where
> is this information stored?
> --
> The Spirit gives life; the flesh counts for nothing! (Jn 6:63)
|||Then, this info is stored in the registry? I would prefer to stay within
SQL, where i can use the xp_regread(). Where in the registry is the
information stored?
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)
"Linchi Shea" wrote:
[vbcol=seagreen]
> There are many programming interfaces to that property. I typically like to
> use command line utility to grab the information from each server, and parse
> the text for the service account info. For instance, you can use NT resource
> kit tool sc.exe for this purpose.
> Linchi
> "Blue Sky" wrote:
|||Execute something like this on your SQL Server instance:
DECLARE @.key nvarchar(100)
SELECT @.key = 'SYSTEM\CurrentControlSet\Services\' +
CASE @.@.SERVICENAME
WHEN 'MSSQLSERVER' THEN 'MSSQLSERVER'
ELSE 'MSSQL$' + @.@.SERVICENAME
END
SELECT @.key
DECLARE @.test varchar(20)
EXEC master..xp_regread @.rootkey='HKEY_LOCAL_MACHINE',
@.key= @.key,
@.value_name='ObjectName',
@.value=@.test OUTPUT
SELECT @.test
Regards
Pawel Potasinski
[http://www.potasinski.pl]
Uytkownik "Blue Sky" <BlueSky@.discussions.microsoft.com> napisa w
wiadomoci news:4A6CB5CF-2203-42B1-B209-E9EEB8125632@.microsoft.com...
>I have over 60 servers and am looking for some code that will allow me to
> query for the Startup Account user ('system' or some domain account).
> Where
> is this information stored?
> --
> The Spirit gives life; the flesh counts for nothing! (Jn 6:63)

Programmatically determine Startup Account

I have over 60 servers and am looking for some code that will allow me to
query for the Startup Account user ('system' or some domain account). Where
is this information stored?
--
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)There are many programming interfaces to that property. I typically like to
use command line utility to grab the information from each server, and parse
the text for the service account info. For instance, you can use NT resource
kit tool sc.exe for this purpose.
Linchi
"Blue Sky" wrote:

> I have over 60 servers and am looking for some code that will allow me to
> query for the Startup Account user ('system' or some domain account). Whe
re
> is this information stored?
> --
> The Spirit gives life; the flesh counts for nothing! (Jn 6:63)|||Then, this info is stored in the registry? I would prefer to stay within
SQL, where i can use the xp_regread(). Where in the registry is the
information stored?
--
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)
"Linchi Shea" wrote:
[vbcol=seagreen]
> There are many programming interfaces to that property. I typically like t
o
> use command line utility to grab the information from each server, and par
se
> the text for the service account info. For instance, you can use NT resour
ce
> kit tool sc.exe for this purpose.
> Linchi
> "Blue Sky" wrote:
>|||Execute something like this on your SQL Server instance:
DECLARE @.key nvarchar(100)
SELECT @.key = 'SYSTEM\CurrentControlSet\Services' +
CASE @.@.SERVICENAME
WHEN 'MSSQLSERVER' THEN 'MSSQLSERVER'
ELSE 'MSSQL$' + @.@.SERVICENAME
END
SELECT @.key
DECLARE @.test varchar(20)
EXEC master..xp_regread @.rootkey='HKEY_LOCAL_MACHINE',
@.key= @.key,
@.value_name='ObjectName',
@.value=@.test OUTPUT
SELECT @.test
Regards
Pawel Potasinski
[http://www.potasinski.pl]
Uytkownik "Blue Sky" <BlueSky@.discussions.microsoft.com> napisa w
wiadomoci news:4A6CB5CF-2203-42B1-B209-E9EEB8125632@.microsoft.com...
>I have over 60 servers and am looking for some code that will allow me to
> query for the Startup Account user ('system' or some domain account).
> Where
> is this information stored?
> --
> The Spirit gives life; the flesh counts for nothing! (Jn 6:63)

Programmatically determine Startup Account

I have over 60 servers and am looking for some code that will allow me to
query for the Startup Account user ('system' or some domain account). Where
is this information stored?
--
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)There are many programming interfaces to that property. I typically like to
use command line utility to grab the information from each server, and parse
the text for the service account info. For instance, you can use NT resource
kit tool sc.exe for this purpose.
Linchi
"Blue Sky" wrote:
> I have over 60 servers and am looking for some code that will allow me to
> query for the Startup Account user ('system' or some domain account). Where
> is this information stored?
> --
> The Spirit gives life; the flesh counts for nothing! (Jn 6:63)|||Then, this info is stored in the registry? I would prefer to stay within
SQL, where i can use the xp_regread(). Where in the registry is the
information stored?
--
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)
"Linchi Shea" wrote:
> There are many programming interfaces to that property. I typically like to
> use command line utility to grab the information from each server, and parse
> the text for the service account info. For instance, you can use NT resource
> kit tool sc.exe for this purpose.
> Linchi
> "Blue Sky" wrote:
> > I have over 60 servers and am looking for some code that will allow me to
> > query for the Startup Account user ('system' or some domain account). Where
> > is this information stored?
> > --
> > The Spirit gives life; the flesh counts for nothing! (Jn 6:63)|||Execute something like this on your SQL Server instance:
DECLARE @.key nvarchar(100)
SELECT @.key = 'SYSTEM\CurrentControlSet\Services\' +
CASE @.@.SERVICENAME
WHEN 'MSSQLSERVER' THEN 'MSSQLSERVER'
ELSE 'MSSQL$' + @.@.SERVICENAME
END
SELECT @.key
DECLARE @.test varchar(20)
EXEC master..xp_regread @.rootkey='HKEY_LOCAL_MACHINE',
@.key= @.key,
@.value_name='ObjectName',
@.value=@.test OUTPUT
SELECT @.test
--
Regards
Pawel Potasinski
[http://www.potasinski.pl]
U¿ytkownik "Blue Sky" <BlueSky@.discussions.microsoft.com> napisa³ w
wiadomo¶ci news:4A6CB5CF-2203-42B1-B209-E9EEB8125632@.microsoft.com...
>I have over 60 servers and am looking for some code that will allow me to
> query for the Startup Account user ('system' or some domain account).
> Where
> is this information stored?
> --
> The Spirit gives life; the flesh counts for nothing! (Jn 6:63)

Wednesday, March 7, 2012

Programmatically create a Data Driven Subscription

Hi,
I have seen the examples of creating a Subscription via code.
I actually wish to create a data driven subscription. Can someone point me
to an example of this or post me an example?
many thanks
MattFound an example.
Have question on this though, how to set the data source to a shared data
source rather than a literal?
I assume you need to use DataSourceDefinitionOrReference rather than
dataSourceDefinition. How do you populate this?
"Matt" <NoSpam:Matthew.Moran@.Computercorp.com.au> wrote in message
news:%23vHHGkbeEHA.3616@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I have seen the examples of creating a Subscription via code.
> I actually wish to create a data driven subscription. Can someone point
me
> to an example of this or post me an example?
> many thanks
> Matt
>|||Got it. Sorry pls ignore
"Matt" <NoSpam:Matthew.Moran@.Computercorp.com.au> wrote in message
news:uAx8KaceEHA.1424@.tk2msftngp13.phx.gbl...
> Found an example.
> Have question on this though, how to set the data source to a shared data
> source rather than a literal?
> I assume you need to use DataSourceDefinitionOrReference rather than
> dataSourceDefinition. How do you populate this?
>
> "Matt" <NoSpam:Matthew.Moran@.Computercorp.com.au> wrote in message
> news:%23vHHGkbeEHA.3616@.TK2MSFTNGP10.phx.gbl...
> > Hi,
> >
> > I have seen the examples of creating a Subscription via code.
> >
> > I actually wish to create a data driven subscription. Can someone point
> me
> > to an example of this or post me an example?
> >
> > many thanks
> >
> > Matt
> >
> >
>

Programmatically altering object code

Has anyone developed a way to programmatically alter the code for multiple
stored procs, functions, etc.?
For example: suppose your database contains hundreds of stored procedures
which access a certain table. Along comes a requirement to rename this
table. It's a lot of tedious work to have to individually open each proc in
QA/EM and change the code. I would like to be able to simply type something
like:
EXEC sp_alter_proc_code 'OldTable', 'NewTable'
And presto, all procs that contain SQL statements that query OldTable are
now pointing to NewTable!
Note that you cannot run an UPDATE statement against syscomment's text field
(e.g., UPDATE syscomments SET text = REPLACE(text, 'OldTable', 'NewTable')),
since this is a computed field.
One solution that I had experimented with was to capture the contents of
syscomment's text column into a variable, run REPLACE against that variable,
and EXEC it. But the problem with that is, a variable can hold only 8000
characters.
I would be interested to hear if anyone has developed a workable solution
for this.>It's a lot of tedious work to have to individually open each proc in
>QA/EM and change the code.
Script all the procs out into a single file as CREATEs (without the
delete!) Open the script in Query Analyzer. Change all the CREATE
PROCs to ALTER PROC. Change all occurances of the old table name to
the new table name - there is a REPLACE ALL feature.
Execute the script.
Roy Harvey
Beacon Falls, CT|||CadeBryant wrote:
> Has anyone developed a way to programmatically alter the code for
> multiple stored procs, functions, etc.?
> For example: suppose your database contains hundreds of stored
> procedures which access a certain table. Along comes a requirement
> to rename this table. It's a lot of tedious work to have to
> individually open each proc in QA/EM and change the code. I would
> like to be able to simply type something like:
> EXEC sp_alter_proc_code 'OldTable', 'NewTable'
> And presto, all procs that contain SQL statements that query OldTable
> are now pointing to NewTable!
> Note that you cannot run an UPDATE statement against syscomment's
> text field (e.g., UPDATE syscomments SET text = REPLACE(text,
> 'OldTable', 'NewTable')), since this is a computed field.
> One solution that I had experimented with was to capture the contents
> of syscomment's text column into a variable, run REPLACE against that
> variable, and EXEC it. But the problem with that is, a variable can
> hold only 8000 characters.
> I would be interested to hear if anyone has developed a workable
> solution for this.
If you are managing your stored procedures using version control
software outside of SQL Server, then you can simply perform a find and
replace. You really should not be managing your procedures using SQL
Server. If you are, I would recommend you extract all procedures and get
them in some form of version control software before beginning this
process.
David Gugick - SQL Server MVP
Quest Software

Programmatically Accessing an SQLDataSource with a "SELECT COUNT(*)" query.

I've found example code of accessing an SQLDataSource and even have it working in my own code - an example would be

Dim datastuff As DataView = CType(srcSoftwareSelected.Select(DataSourceSelectArguments.Empty), DataView)

Dim row As DataRow = datastuff.Table.Rows(0)
Dim installtype As Integer = row("InstallMethod")
Dim install As String = row("Install").ToString
Dim notes As String = row("Notes").ToString

The above only works on a single row, of course. If I needed more, I know I can loop it.

The query in srcSoftwareSelected is something like "SELECT InstallMethod, Install, Notes FROM Software"

My problem lies in trying to access the data in a simliar way when I'm using a SELECT COUNT query.

Dim datastuff As DataView = CType(srcSoftwareUsage.Select(DataSourceSelectArguments.Empty), DataView)
Dim row As DataRow = datastuff.Table.Rows(0)
Dim count As Integer = row("rowcnt")

The query here is "SELECT COUNT(*) as rowcnt FROM Software"

The variable count is 1 every time I query this, no matter what the actual count is. I know I've got to be accessing the incorrect data member in the 2nd query because a gridview tied to srcSoftwareUsage (the SQLDataSource) always displays the correct value.

Where am I going wrong here?


The following should work.

Dim datastuffAs System.Data.DataView =CType(srcSoftwareUsage.Select(DataSourceSelectArguments.Empty), System.Data.DataView)

Dim drAs System.Data.DataRow = datastuff .Table.Rows(0)

Dim mycountAsString = Convert.ToInt32(dr("rowcnt")).ToString()

'Label1.Text = mycount

|||

Hi there,

Aren't you getting the row count from your SELECT COUNT query (1 row obviously)? Instead of getting the result value from that query?

gonzzas

|||

It's very similar to what I've tested out, but that exact code will show that mycount = "1" instead of the actual value.

What is interesting is the GridView control I set up on the test page is outputting the correct result.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="srcSoftwareUsage" Width="527px">
<Columns>
<asp:BoundField DataField="rowcnt" HeaderText="rowcnt" ReadOnly="True" SortExpression="rowcnt" />
</Columns>
</asp:GridView>

Now, it's obviously accessing the column named rowcnt. I can debug my code and manually look at the column values in DataView.Table.Rows(0) and it shows the value 1 and nothing more.

|||

Yes, I can use either code to get the correct count from my query. What is your SqlDataSource code?

Here is what I tested:

Dim dvAs System.Data.DataView =CType(SqlDataSource2.Select(DataSourceSelectArguments.Empty), System.Data.DataView)

Dim rowAs System.Data.DataRow = dv.Table.Rows(0)

' For Each row As System.Data.DataRow In dv.Table.Rows

Dim mycountAsString = Convert.ToInt32(row("rowcnt")).ToString()

Label2.Text = mycount

' Next

|||

Murphy's Law probably applies as I didn't give you thecomplete story - I naively thought this part shouldn't matter as it'sthe table output is identical.

It appears to be my sql query.

I'm not actually looking for the count of rows in the Software table, but I'm looking for the count of times a particular row in Software is referenced by 2 other tables - RoleSoft and TeamSoft

With my simple query above, both the code and GridView worked. With this one - the GridView works, the code doesn't.

SELECT COUNT(*) AS rowcnt FROM (SELECT Role, Software FROM RoleSoft WHERE (Software = @.Id) UNION ALL SELECT Team, Software FROM TeamSoft WHERE (Software = @.Id)) AS derivedtbl_1

I thought it was a moot point as the table output appears identical from each query. Obviously I'm wrong. I'm imagining the derivedtbl_1 is probably where I'm getting bogus data in the code.

1> SELECT COUNT(*) AS rowcnt FROM (SELECT Role, Software FROM RoleSoft WHERE (Software = 2) UNION ALL SELECT Team, Software FROM TeamSoft WHERE (Software = 2))
AS derivedtbl_1
2> go
rowcnt
----
3

(1 rows affected)
1> SELECT COUNT(*) as rowcnt FROM Software
2> go
rowcnt
----
8

(1 rows affected)

|||

Bah. I figured it out. It wasn't even the SQL statement. I had updated the @.Id parameter in the srcSoftwareUsage_Selecting event handler and I misused a global variable. It kept setting @.Id to 1 and the count for that Id was always 1.

Now I feel stupid for wasting your time and mine on this. Thanks for the help, though.

Programmatically aborting a package

Can a package executed from code be aborted in code? The Package class has an Execute() method but no Abort() method. Clearly the debugger can stop a package at any point, so it must be possible somehow.

Are you trying to capture an error and then halt? If so, there's always the FireError event that can be thrown.|||

JeffJohnsonMVPVB wrote:

Can a package executed from code be aborted in code? The Package class has an Execute() method but no Abort() method. Clearly the debugger can stop a package at any point, so it must be possible somehow.

You're right, the debugger can do that but it might be a misnomer to think that that is the same as aborting from within thw package.

I presume that your abort code would be conditional so I would suggest that the best way to achieve what you want is to use conditional precedence constraints. If you need any help with those, feel free to reply.

-Jamie

|||

Okay, I need to expound. I have created a Windows service that executes SSIS packages. Many of these are long-running, perhaps for hours. If an operator realizes that something is wrong after submitting a package, I'd like to allow him to send a cancel request to the service and then have the service stop the package. What I do NOT want to do is code every single precedence constraint to check for an "abort" flag (and I'm not sure I'd even know how to set such a flag once the package has started without putting an MSMQ task or the like between each executable--yuck!). Could I simply kill the thread that is executing the package? That seems "dirty," and I was hoping for a cleaner method.

|||

I've taken a look at the application class (http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.application_members.aspx) and the package class (http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.package_members.aspx) and I don't see anything in there that would help.

I can understand why. An executing SSIS package is meant to be a batch/unattended process - once its running you just leave it to get on with it. I fear killing the process might be the way to go.

If you didn't want to put a conditional precedence constraint onto every executable then another option might be to put the executable that conditionally "kills" the package into the package container's OnPostExecute eventhandler. This *could* potentially be a little bit more "graceful" about it than just killing the process. Might be worth a try.

-Jamie

|||

There is a cleaner method. Call RunningPackage.Stop().|||

If your service is starting processes asynchronously your best bet is track the process id. The service could check periodically if the process had ended and "forget" the process if it had. That would give you a way to track what was currently running as well as select a process to kill.. If you want something intelligent in your logging, just have the service write to whatever you use for logging once the process has gone away. Maybe something like *** Operator Canceled ***|||

jaegd wrote:

There is a cleaner method. Call RunningPackage.Stop().

Does this work for file system based packages executed from command line dtexec or otherwise?|||

That looks perfect. I should've scanned the class library reference more thoroughly. I'll try to remember to let everyone know how it works.

(Clearly I don't know how to use the quoting feature, sorry.)

|||

Follow-up question: does anyone know if SSIS raises any particular events when RunningPackage.Stop is called? I could trap these events in my custom tasks and fail them cleanly if so.

|||

Yes the SSIS runtime does signal an event when RunningPackage.Stop() is called. You can get at that event by polling periodically -- call to FireQueryCancel() in a custom task, let's say, at strategic points.

If you don't want to poll, you could wrap the the system variable System::CancelEvent in a SafeHandle and wait for the event to be signalled. That also works.

SSIS stock tasks vary at the frequency which they check if the package's Cancel event has been signalled, but they do check it periodically (no, its not documented the frequency at which the runtime check's the cancel event's state).

|||

RunningPackage.Stop() works on package invoked by any "mechanism", since its the same runtime. That includes command line, BIDS, custom invocation util (whatever you can dream up, e.g. web service, windows service), not to mention in-process or out-of-process package executions via Execute Package tasks.

Programmatic Render of Reports into PDF format

Hi,
Can anybody please convert the following C# code into VB.Net Code.I tried
but its saying Object Reference not set to an instance of an object.
Or give me VB.NET(Web Application, CodeBehind:VB.Net) code to
programmatically render reports into PDF format.
// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "Parameter1";
parameters[0].Value = Request.QueryString["id"];
Thanks
Rajesh YDim Parameters(1) As New ParameterValue
Parameters(0) = New ParameterValue
Parameters(0).Name = "Parameter1"
Parameters(0).Value = Request.QueryString("id")
"Rajesh Yennam" wrote:
> Hi,
> Can anybody please convert the following C# code into VB.Net Code.I tried
> but its saying Object Reference not set to an instance of an object.
> Or give me VB.NET(Web Application, CodeBehind:VB.Net) code to
> programmatically render reports into PDF format.
> // Prepare report parameter.
> ParameterValue[] parameters = new ParameterValue[1];
> parameters[0] = new ParameterValue();
> parameters[0].Name = "Parameter1";
> parameters[0].Value = Request.QueryString["id"];
> Thanks
> Rajesh Y|||Hi Rajesh:
I'd suspect the line of code :
parameters[0].Value = Request.QueryString["id"];
I'd guess you do not have an id parameter in the query string. Double
check the query string.
HTH,
--
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 29 Oct 2004 03:43:01 -0700, "Rajesh Yennam"
<RajeshYennam@.discussions.microsoft.com> wrote:
>Hi,
>Can anybody please convert the following C# code into VB.Net Code.I tried
>but its saying Object Reference not set to an instance of an object.
>Or give me VB.NET(Web Application, CodeBehind:VB.Net) code to
>programmatically render reports into PDF format.
>// Prepare report parameter.
> ParameterValue[] parameters = new ParameterValue[1];
> parameters[0] = new ParameterValue();
> parameters[0].Name = "Parameter1";
> parameters[0].Value = Request.QueryString["id"];
>Thanks
>Rajesh Y

Saturday, February 25, 2012

Programmatic access to the code SQLCMD uses to parse sql into batches

Hi,

I am thinking of writing a C# Windows app to iterate a set of sql scripts and submit them to SQL Server. Many scripts have "go" as a batch delimiter. I could probably figure out a regular expression to parse for that delimiter, but it seems tricky (need to exclude 'go', -- go, /* go */, etc). Obviously SQLCMD and Management Studio have a way to do this. I was wondering if that's exposed in an API anywhere. I looked into the SMO object model, but I couldn't find it.

Thanks much,

Mike

Hi,

thats no mafic, just use the SET PARSEONLY statement before your statements to check.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de

|||

As far as I can tell "set parseonly on" just checks the syntax. I want to get back a collection of strings to submit, each one a proper batch. Eg:

select 'Inside quotes, go or " go " or '' go '' is not a delimiter ' as go -- not go here

select 'Second go '

go

select 'Another batch here /* go */ go '

go

In query analyzer or management studio this appropriately returns 3 result sets, presumably executed as 2 batches. I would like to identify the first 2 lines as one batch, and the second select as another batch.

Mike

Programmatic Access to SQL database


New at this and would like to get the code in VB or . Net which would
allow connection, reading and writing to a SQL database previously
created.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!Try taking a look here, there are many examples to choose from...
http://gotdotnet.com/Community/User...?query=database
"John Brown" wrote:

>
> New at this and would like to get the code in VB or . Net which would
> allow connection, reading and writing to a SQL database previously
> created.
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
>