Showing posts with label stored. Show all posts
Showing posts with label stored. Show all posts

Thursday, March 29, 2012

Draw Bitmap from Points in report

Hi, i have a database field that has a drawing stored as points, for example....

(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)

In my VB.NET application, i can take those points and recreate the image. I need to do the same in reporting services... i am trying to replace a legacy ACCESS report, that had the drawing object.

How can i recreate the image in reporting services? is there an easy way to do so? i believe i tried to create a class and tried to reference it and call the function to return the data as an image, but i got a system.drawing not found error...

There are at least two options:

1. use the built-in charts with chart type = scatter. Note: the scatter chart must have a category grouping based on a unique value (e.g. data point id in your case). I attached a small sample report to the bottom of this posting to show the idea.

2. or draw the image yourself and use it in Reporting Services. However, make sure to follow these steps:

2.1. Design and implement a custom assembly to generate images.
The custom assembly must retrieve the data on its own, take care of grouping/sorting the data, and generating the chart image.
Note: The custom assembly has to return the image as byte[]. It cannot return it as a System.Drawing.Image. You can often convert a System.Drawing.Image object with code similar to the following.
System.IO.MemoryStream renderedImage = new MemoryStream();
myChart.Save(renderedImage);
renderedImage.Position = 0;
return renderedImage.ToArray();

2.2. Add an image to the report.
Set the image type to Database. If the generated image is a bitmap in the PNG image format, set the image mimetype property to “image/png.” For the image value property, use an expression like the following.
=MyCustomAssembly.GenerateChart()

2.3. View the report in Report Designer Preview view to verify that the report is working correctly.
Note: In a default configuration, custom assemblies run in FullTrust in Report Designer preview. Hence, operations that require certain code access security permissions (such as file input/output, data provide access, etc.) are automatically granted these permissions in Fulltrust.

2.4. Deploy the custom assembly on a report server.
Make sure that the security policy configuration of the report server grants sufficient permissions to your custom assembly at runtime; otherwise the image generation will fail. For more information, see Understanding Code Access Security in Reporting Services (http://msdn2.microsoft.com/en-us/library/ms155108.aspx) in SQL Server 2005 Books Online.

-- Robert

=========================================

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<DataSources>
<DataSource Name="AdventureWorks">
<DataSourceReference>AdventureWorks</DataSourceReference>
<rd:DataSourceID>67061ec4-b72e-4a04-a7f3-714536211b9c</rd:DataSourceID>
</DataSource>
</DataSources>
<BottomMargin>1in</BottomMargin>
<RightMargin>1in</RightMargin>
<rd:DrawGrid>true</rd:DrawGrid>
<InteractiveWidth>8.5in</InteractiveWidth>
<rd:SnapToGrid>true</rd:SnapToGrid>
<Body>
<ReportItems>
<Chart Name="chart1">
<Legend>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
<Position>RightCenter</Position>
</Legend>
<Subtype>Line</Subtype>
<Title />
<Height>2in</Height>
<CategoryAxis>
<Axis>
<Title />
<Style>
<Format>MMM dd</Format>
</Style>
<MajorGridLines>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
</MajorGridLines>
<MinorGridLines>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
</MinorGridLines>
<MajorTickMarks>Outside</MajorTickMarks>
<Visible>true</Visible>
<Scalar>true</Scalar>
</Axis>
</CategoryAxis>
<PointWidth>0</PointWidth>
<Left>0.125in</Left>
<ThreeDProperties>
<Rotation>30</Rotation>
<Inclination>30</Inclination>
<Shading>Simple</Shading>
<WallThickness>50</WallThickness>
</ThreeDProperties>
<DataSetName>DataSet1</DataSetName>
<SeriesGroupings>
<SeriesGrouping>
<StaticSeries>
<StaticMember>
<Label>Value1</Label>
</StaticMember>
</StaticSeries>
</SeriesGrouping>
</SeriesGroupings>
<Top>0.125in</Top>
<PlotArea>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
<BackgroundColor>WhiteSmoke</BackgroundColor>
<BackgroundGradientEndColor>White</BackgroundGradientEndColor>
<BackgroundGradientType>TopBottom</BackgroundGradientType>
</Style>
</PlotArea>
<ValueAxis>
<Axis>
<Title />
<MajorGridLines>
<ShowGridLines>true</ShowGridLines>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
</MajorGridLines>
<MinorGridLines>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
</MinorGridLines>
<MajorTickMarks>Outside</MajorTickMarks>
<Min>0</Min>
<MajorInterval>5</MajorInterval>
<Margin>true</Margin>
<Visible>true</Visible>
<Scalar>true</Scalar>
</Axis>
</ValueAxis>
<Type>Scatter</Type>
<Width>3.5in</Width>
<CategoryGroupings>
<CategoryGrouping>
<DynamicCategories>
<Grouping Name="chart1_CategoryGroup1">
<GroupExpressions>
<GroupExpression>=Fields!MeasurementId.Value</GroupExpression>
</GroupExpressions>
</Grouping>
<Sorting>
<SortBy>
<SortExpression>=CDate(Fields!TimeStamp.Value)</SortExpression>
<Direction>Ascending</Direction>
</SortBy>
</Sorting>
<Label>=Fields!MeasurementId.Value</Label>
</DynamicCategories>
</CategoryGrouping>
</CategoryGroupings>
<Palette>EarthTones</Palette>
<ChartData>
<ChartSeries>
<DataPoints>
<DataPoint>
<DataValues>
<DataValue>
<Value>=CDate(Fields!TimeStamp.Value)</Value>
</DataValue>
<DataValue>
<Value>=Fields!Value.Value</Value>
</DataValue>
</DataValues>
<DataLabel />
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
<BorderWidth>
<Default>4.5pt</Default>
</BorderWidth>
</Style>
<Marker>
<Size>6pt</Size>
</Marker>
</DataPoint>
</DataPoints>
</ChartSeries>
</ChartData>
<Style>
<BackgroundColor>White</BackgroundColor>
</Style>
</Chart>
</ReportItems>
<Height>2.25in</Height>
</Body>
<rd:ReportID>a068be44-d5ee-4243-91ed-445f05622d2c</rd:ReportID>
<LeftMargin>1in</LeftMargin>
<DataSets>
<DataSet Name="DataSet1">
<Query>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
<CommandText>select 1 as MeasurementId, '07/16/2006' as TimeStamp, 10 as Value union
select 2 as MeasurementId, '07/17/2006' as TimeStamp, 10 as Value union
select 3 as MeasurementId, '07/17/2006' as TimeStamp, 8 as Value union
select 4 as MeasurementId, '07/18/2006' as TimeStamp, 8 as Value union
select 5 as MeasurementId, '07/19/2006' as TimeStamp, 10 as Value union
select 6 as MeasurementId, '07/19/2006' as TimeStamp, 12 as Value union
select 7 as MeasurementId, '07/20/2006' as TimeStamp, 12 as Value union
select 8 as MeasurementId, '07/21/2006' as TimeStamp, 12 as Value union
select 9 as MeasurementId, '07/21/2006' as TimeStamp, 9 as Value union
select 10 as MeasurementId, '07/22/2006' as TimeStamp, 9 as Value</CommandText>
<DataSourceName>AdventureWorks</DataSourceName>
</Query>
<Fields>
<Field Name="MeasurementId">
<rd:TypeName>System.Int32</rd:TypeName>
<DataField>MeasurementId</DataField>
</Field>
<Field Name="TimeStamp">
<rd:TypeName>System.String</rd:TypeName>
<DataField>TimeStamp</DataField>
</Field>
<Field Name="Value">
<rd:TypeName>System.Int32</rd:TypeName>
<DataField>Value</DataField>
</Field>
</Fields>
</DataSet>
</DataSets>
<Author>Robert M. Bruckner, Microsoft</Author>
<Width>3.75in</Width>
<InteractiveHeight>11in</InteractiveHeight>
<Language>en-US</Language>
<TopMargin>1in</TopMargin>
</Report>

|||

Thanks for posting a reply ill try it first thing in the morning....

The drawing is collected on a handheld, its actually a signature (but it can be a drawing as well, so lots of points....), the coordinates of the drawing are saved in an xml file along with other data, and is then inserted into the database when the device is synced....

ill try the chart way first, and then the custom assembly again. when i tried it last time it was giving me the bitmap not defined error, i dont remember if i was returning the data as an image or as a byte... :) ill give it a try and post back here so that someone else can also make use of your help!

thank you.

|||omg...... thats for the reply and the hints, i doublechecked everything in your 2nd suggestion with what i had already done, the first one wasnt feasible... and after checking all your suggestions i realised that it had been working all this time!!!., it just doesnt work in DEBUG mode... :( when i ran the application itself outside of VS, it ran with no problems!!!!|||Make sure you have copied your assembly to the C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies folder.

Draw Bitmap from Points in report

Hi, i have a database field that has a drawing stored as points, for example....

(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)(x1,y1)(x2,x2)

In my VB.NET application, i can take those points and recreate the image. I need to do the same in reporting services... i am trying to replace a legacy ACCESS report, that had the drawing object.

How can i recreate the image in reporting services? is there an easy way to do so? i believe i tried to create a class and tried to reference it and call the function to return the data as an image, but i got a system.drawing not found error...

There are at least two options:

1. use the built-in charts with chart type = scatter. Note: the scatter chart must have a category grouping based on a unique value (e.g. data point id in your case). I attached a small sample report to the bottom of this posting to show the idea.

2. or draw the image yourself and use it in Reporting Services. However, make sure to follow these steps:

2.1. Design and implement a custom assembly to generate images.
The custom assembly must retrieve the data on its own, take care of grouping/sorting the data, and generating the chart image.
Note: The custom assembly has to return the image as byte[]. It cannot return it as a System.Drawing.Image. You can often convert a System.Drawing.Image object with code similar to the following.
System.IO.MemoryStream renderedImage = new MemoryStream();
myChart.Save(renderedImage);
renderedImage.Position = 0;
return renderedImage.ToArray();

2.2. Add an image to the report.
Set the image type to Database. If the generated image is a bitmap in the PNG image format, set the image mimetype property to “image/png.” For the image value property, use an expression like the following.
=MyCustomAssembly.GenerateChart()

2.3. View the report in Report Designer Preview view to verify that the report is working correctly.
Note: In a default configuration, custom assemblies run in FullTrust in Report Designer preview. Hence, operations that require certain code access security permissions (such as file input/output, data provide access, etc.) are automatically granted these permissions in Fulltrust.

2.4. Deploy the custom assembly on a report server.
Make sure that the security policy configuration of the report server grants sufficient permissions to your custom assembly at runtime; otherwise the image generation will fail. For more information, see Understanding Code Access Security in Reporting Services (http://msdn2.microsoft.com/en-us/library/ms155108.aspx) in SQL Server 2005 Books Online.

-- Robert

=========================================

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<DataSources>
<DataSource Name="AdventureWorks">
<DataSourceReference>AdventureWorks</DataSourceReference>
<rd:DataSourceID>67061ec4-b72e-4a04-a7f3-714536211b9c</rd:DataSourceID>
</DataSource>
</DataSources>
<BottomMargin>1in</BottomMargin>
<RightMargin>1in</RightMargin>
<rd:DrawGrid>true</rd:DrawGrid>
<InteractiveWidth>8.5in</InteractiveWidth>
<rd:SnapToGrid>true</rd:SnapToGrid>
<Body>
<ReportItems>
<Chart Name="chart1">
<Legend>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
<Position>RightCenter</Position>
</Legend>
<Subtype>Line</Subtype>
<Title />
<Height>2in</Height>
<CategoryAxis>
<Axis>
<Title />
<Style>
<Format>MMM dd</Format>
</Style>
<MajorGridLines>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
</MajorGridLines>
<MinorGridLines>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
</MinorGridLines>
<MajorTickMarks>Outside</MajorTickMarks>
<Visible>true</Visible>
<Scalar>true</Scalar>
</Axis>
</CategoryAxis>
<PointWidth>0</PointWidth>
<Left>0.125in</Left>
<ThreeDProperties>
<Rotation>30</Rotation>
<Inclination>30</Inclination>
<Shading>Simple</Shading>
<WallThickness>50</WallThickness>
</ThreeDProperties>
<DataSetName>DataSet1</DataSetName>
<SeriesGroupings>
<SeriesGrouping>
<StaticSeries>
<StaticMember>
<Label>Value1</Label>
</StaticMember>
</StaticSeries>
</SeriesGrouping>
</SeriesGroupings>
<Top>0.125in</Top>
<PlotArea>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
<BackgroundColor>WhiteSmoke</BackgroundColor>
<BackgroundGradientEndColor>White</BackgroundGradientEndColor>
<BackgroundGradientType>TopBottom</BackgroundGradientType>
</Style>
</PlotArea>
<ValueAxis>
<Axis>
<Title />
<MajorGridLines>
<ShowGridLines>true</ShowGridLines>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
</MajorGridLines>
<MinorGridLines>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
</Style>
</MinorGridLines>
<MajorTickMarks>Outside</MajorTickMarks>
<Min>0</Min>
<MajorInterval>5</MajorInterval>
<Margin>true</Margin>
<Visible>true</Visible>
<Scalar>true</Scalar>
</Axis>
</ValueAxis>
<Type>Scatter</Type>
<Width>3.5in</Width>
<CategoryGroupings>
<CategoryGrouping>
<DynamicCategories>
<Grouping Name="chart1_CategoryGroup1">
<GroupExpressions>
<GroupExpression>=Fields!MeasurementId.Value</GroupExpression>
</GroupExpressions>
</Grouping>
<Sorting>
<SortBy>
<SortExpression>=CDate(Fields!TimeStamp.Value)</SortExpression>
<Direction>Ascending</Direction>
</SortBy>
</Sorting>
<Label>=Fields!MeasurementId.Value</Label>
</DynamicCategories>
</CategoryGrouping>
</CategoryGroupings>
<Palette>EarthTones</Palette>
<ChartData>
<ChartSeries>
<DataPoints>
<DataPoint>
<DataValues>
<DataValue>
<Value>=CDate(Fields!TimeStamp.Value)</Value>
</DataValue>
<DataValue>
<Value>=Fields!Value.Value</Value>
</DataValue>
</DataValues>
<DataLabel />
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
<BorderWidth>
<Default>4.5pt</Default>
</BorderWidth>
</Style>
<Marker>
<Size>6pt</Size>
</Marker>
</DataPoint>
</DataPoints>
</ChartSeries>
</ChartData>
<Style>
<BackgroundColor>White</BackgroundColor>
</Style>
</Chart>
</ReportItems>
<Height>2.25in</Height>
</Body>
<rd:ReportID>a068be44-d5ee-4243-91ed-445f05622d2c</rd:ReportID>
<LeftMargin>1in</LeftMargin>
<DataSets>
<DataSet Name="DataSet1">
<Query>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
<CommandText>select 1 as MeasurementId, '07/16/2006' as TimeStamp, 10 as Value union
select 2 as MeasurementId, '07/17/2006' as TimeStamp, 10 as Value union
select 3 as MeasurementId, '07/17/2006' as TimeStamp, 8 as Value union
select 4 as MeasurementId, '07/18/2006' as TimeStamp, 8 as Value union
select 5 as MeasurementId, '07/19/2006' as TimeStamp, 10 as Value union
select 6 as MeasurementId, '07/19/2006' as TimeStamp, 12 as Value union
select 7 as MeasurementId, '07/20/2006' as TimeStamp, 12 as Value union
select 8 as MeasurementId, '07/21/2006' as TimeStamp, 12 as Value union
select 9 as MeasurementId, '07/21/2006' as TimeStamp, 9 as Value union
select 10 as MeasurementId, '07/22/2006' as TimeStamp, 9 as Value</CommandText>
<DataSourceName>AdventureWorks</DataSourceName>
</Query>
<Fields>
<Field Name="MeasurementId">
<rd:TypeName>System.Int32</rd:TypeName>
<DataField>MeasurementId</DataField>
</Field>
<Field Name="TimeStamp">
<rd:TypeName>System.String</rd:TypeName>
<DataField>TimeStamp</DataField>
</Field>
<Field Name="Value">
<rd:TypeName>System.Int32</rd:TypeName>
<DataField>Value</DataField>
</Field>
</Fields>
</DataSet>
</DataSets>
<Author>Robert M. Bruckner, Microsoft</Author>
<Width>3.75in</Width>
<InteractiveHeight>11in</InteractiveHeight>
<Language>en-US</Language>
<TopMargin>1in</TopMargin>
</Report>

|||

Thanks for posting a reply ill try it first thing in the morning....

The drawing is collected on a handheld, its actually a signature (but it can be a drawing as well, so lots of points....), the coordinates of the drawing are saved in an xml file along with other data, and is then inserted into the database when the device is synced....

ill try the chart way first, and then the custom assembly again. when i tried it last time it was giving me the bitmap not defined error, i dont remember if i was returning the data as an image or as a byte... :) ill give it a try and post back here so that someone else can also make use of your help!

thank you.

|||omg...... thats for the reply and the hints, i doublechecked everything in your 2nd suggestion with what i had already done, the first one wasnt feasible... and after checking all your suggestions i realised that it had been working all this time!!!., it just doesnt work in DEBUG mode... :( when i ran the application itself outside of VS, it ran with no problems!!!!|||Make sure you have copied your assembly to the C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies folder.

Tuesday, March 27, 2012

Downloading shared datasources

If there are multiple developers, can we download the shared data sources
that are stored on the server? Or does each report developer need to create
their own?
Thanks,Hey all the developers can use the same shared datasource but through VSS
then the reports can be well controlled.
Amarnath
"Mark" wrote:
> If there are multiple developers, can we download the shared data sources
> that are stored on the server? Or does each report developer need to create
> their own?
> Thanks,

Sunday, March 25, 2012

Downloading data into a txt file

Dear All,

I have an application running on my mobile device and the data is stored in the mobile database. So now i am trying to build any application on my pc which upon click should download the data from my mobile database into a local text file. Is there any idea or reference where I can stary working on this ?

DataSet ds = new DataSet();

...

DataAdapter da = new DataAdapter(...);

da.Fill(ds, "table1");

...

da.Fill(ds, "tableN");

ds.WriteXml("LocalTextFile.xml");

If XML is not what you want then write data row by row in the format you want using System.IO namespace.

|||

Dear Ilya,

I would prefer it to be in text file format. The problem what project shall I develop I mean in the visual studio 2005. Should it be windows form or device application ? Because if it is device application it cant run in my desktop rite ? So it should be windows form rite ? Thanks.

|||

Dear Ilya,

I have now build a new console application. So then I add a reference to

System.Data.SqlServerCe; to enable me to connect to the mobile database found in the pda. So when I try to run I get an error "Could not load file or assembly 'System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)". The problem is that on the same machine I can compile my device application which is also using the same reference'System.Data.SqlServerCe. Please correct me if I am doing something wrong here. Another thing is that how must I reference the path to my mobile database in the pda ? I am trying like this I dont know if this is right

Mobile Device/MiniSD Card/MiniSD Card/test1/db1.sdf. Thanks.

|||

Dear All,

I have a problem here. What i exactly want to do it that build a console application where when I connect my pda to my desktop and run the exe file it should be able to transfer the .sdf data into a text file of my local desktop ? Is there any code or reference where can guide me ?

|||Some of the components from www.primeworks-mobile.com should be able to help you.|||

Dear ErikEJ,

I would prefer to write on my own as I cant afford third party software. Hope you can show me some light into it. Thanks.

|||What you are going to want to probably do is copy the database from the device to your desktop, then use the sql ce for the desktop libs (remember you can use sql ce on devices and full blown windows) to read through the database and output . You can accomplish copying the database over through code using the Windows CE RAPI. The full framework as far as I know does not have built-in support for it. So what you would need to do is P/Invoke some functions in the rapi.dll. Luckily somebody has essentially done this, look for the opennetcf's (www.opennetcf.org) desktop communication library. So once you use this to get a copy of the database over to your desktop you can use the sql ce for windows (not wm or ce) libs to connect to your now local copy of the database. Then using a SqlCeDataReader you can just iterate through every record in the database, while reading a record in you can format it however you like then push that into a file using a StreamWriter object.
|||

Dear Steve,

Thank you very much for your kind information. So now I have downloaded the OpenNETCF.Desktop.Communication Library . Now how shall I start ? Shall I start by building a console application ? So must I first manually download the database or the system can do it for me ? I am really at lost can your pls guide me further on this. Thanks once again.

|||If you want to do it as a console application then start there. Then my next step would be to use the Desktop Communication library to programmatically get the database from your device to local computer. The communication library should have came with an example application that you can probably look at to find out how they copy files back and forth. You can look their and do the same thing.
|||

Dear Steve,

Ok I have followed and done accordingly and sucessfully download the sdf file into my desktop. My next problem is that i am not able to connect to downloaded .sdf in the desktop. I am using the same code as I build the windows device application. Can your please tell me wat can be my mistake ? For example I use this

SqlCeConnection conn1 = new SqlCeConnection("Data Source = c:/test1.sdf");

First I got an error "Could not load file or assembly 'System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)". Then I manage to solve "Unable to load DLL 'sqlceme30.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)". So wat is the possible error on my side ?

So what can be possible error on my side ? Thanks.

|||

Dear Steve,

I am ok with Desktop Communication library. I have already managed to download the database from the device to my local computer. My next step is that how can I from my console application link to the database which I have already downloaded using the said library. Thanks once again.

|||Once you have the sdf file over to you desktop you can use the desktop version of the sqlce data object. I think you need to download the Microsoft SQL Server Mobile 2005 Mobile Edition SDK. Once you have that downloaded and installed it you should be able to add the proper references to the desktop x86 version of the libraries that you need. Then you should be able to connect to the database and use it just like you did on the handheld with the .NET CF. You should be able to just use a SqlCeDataReader object to query the database then read through the returned records and output them using a StreamWriter object to put them into a text file which you can then control the format of.
|||

Dear Steve,

I have already downloaded the microsoft sql server mobile 2005 mobile edition sdk. So I tried to use the SqlCeDataReader and below is the errors I got. Can you please guide me on this ?

SqlCeConnection conn1 = new SqlCeConnection("Data Source = c:/test1.sdf");

First I got an error "Could not load file or assembly 'System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)". Then I manage to solve that problem but got another one "Unable to load DLL 'sqlceme30.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)". So wat is the possible error on my side ?Thanks.

Downloading data into a txt file

Dear All,

I have an application running on my mobile device and the data is stored in the mobile database. So now i am trying to build any application on my pc which upon click should download the data from my mobile database into a local text file. Is there any idea or reference where I can stary working on this ?

DataSet ds = new DataSet();

...

DataAdapter da = new DataAdapter(...);

da.Fill(ds, "table1");

...

da.Fill(ds, "tableN");

ds.WriteXml("LocalTextFile.xml");

If XML is not what you want then write data row by row in the format you want using System.IO namespace.

|||

Dear Ilya,

I would prefer it to be in text file format. The problem what project shall I develop I mean in the visual studio 2005. Should it be windows form or device application ? Because if it is device application it cant run in my desktop rite ? So it should be windows form rite ? Thanks.

|||

Dear Ilya,

I have now build a new console application. So then I add a reference to

System.Data.SqlServerCe; to enable me to connect to the mobile database found in the pda. So when I try to run I get an error "Could not load file or assembly 'System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)". The problem is that on the same machine I can compile my device application which is also using the same reference'System.Data.SqlServerCe. Please correct me if I am doing something wrong here. Another thing is that how must I reference the path to my mobile database in the pda ? I am trying like this I dont know if this is right

Mobile Device/MiniSD Card/MiniSD Card/test1/db1.sdf. Thanks.

|||

Dear All,

I have a problem here. What i exactly want to do it that build a console application where when I connect my pda to my desktop and run the exe file it should be able to transfer the .sdf data into a text file of my local desktop ? Is there any code or reference where can guide me ?

|||Some of the components from www.primeworks-mobile.com should be able to help you.|||

Dear ErikEJ,

I would prefer to write on my own as I cant afford third party software. Hope you can show me some light into it. Thanks.

|||What you are going to want to probably do is copy the database from the device to your desktop, then use the sql ce for the desktop libs (remember you can use sql ce on devices and full blown windows) to read through the database and output . You can accomplish copying the database over through code using the Windows CE RAPI. The full framework as far as I know does not have built-in support for it. So what you would need to do is P/Invoke some functions in the rapi.dll. Luckily somebody has essentially done this, look for the opennetcf's (www.opennetcf.org) desktop communication library. So once you use this to get a copy of the database over to your desktop you can use the sql ce for windows (not wm or ce) libs to connect to your now local copy of the database. Then using a SqlCeDataReader you can just iterate through every record in the database, while reading a record in you can format it however you like then push that into a file using a StreamWriter object.
|||

Dear Steve,

Thank you very much for your kind information. So now I have downloaded the OpenNETCF.Desktop.Communication Library . Now how shall I start ? Shall I start by building a console application ? So must I first manually download the database or the system can do it for me ? I am really at lost can your pls guide me further on this. Thanks once again.

|||If you want to do it as a console application then start there. Then my next step would be to use the Desktop Communication library to programmatically get the database from your device to local computer. The communication library should have came with an example application that you can probably look at to find out how they copy files back and forth. You can look their and do the same thing.
|||

Dear Steve,

Ok I have followed and done accordingly and sucessfully download the sdf file into my desktop. My next problem is that i am not able to connect to downloaded .sdf in the desktop. I am using the same code as I build the windows device application. Can your please tell me wat can be my mistake ? For example I use this

SqlCeConnection conn1 = new SqlCeConnection("Data Source = c:/test1.sdf");

First I got an error "Could not load file or assembly 'System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)". Then I manage to solve "Unable to load DLL 'sqlceme30.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)". So wat is the possible error on my side ?

So what can be possible error on my side ? Thanks.

|||

Dear Steve,

I am ok with Desktop Communication library. I have already managed to download the database from the device to my local computer. My next step is that how can I from my console application link to the database which I have already downloaded using the said library. Thanks once again.

|||Once you have the sdf file over to you desktop you can use the desktop version of the sqlce data object. I think you need to download the Microsoft SQL Server Mobile 2005 Mobile Edition SDK. Once you have that downloaded and installed it you should be able to add the proper references to the desktop x86 version of the libraries that you need. Then you should be able to connect to the database and use it just like you did on the handheld with the .NET CF. You should be able to just use a SqlCeDataReader object to query the database then read through the returned records and output them using a StreamWriter object to put them into a text file which you can then control the format of.
|||

Dear Steve,

I have already downloaded the microsoft sql server mobile 2005 mobile edition sdk. So I tried to use the SqlCeDataReader and below is the errors I got. Can you please guide me on this ?

SqlCeConnection conn1 = new SqlCeConnection("Data Source = c:/test1.sdf");

First I got an error "Could not load file or assembly 'System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)". Then I manage to solve that problem but got another one "Unable to load DLL 'sqlceme30.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)". So wat is the possible error on my side ?Thanks.

Download the file stored in sqlserver table as image datatype using asp.net 2.0

I am using Asp.net 2.0 with C# and sql server 2000. I need to download the file which is stored in sql server database table as image datatype. So I need to download from cs page.

Pls reply,

Arun.

Here's a good article on storing and retrieving binary data with asp.net 2.0
http://www.beansoftware.com/ASP.NET-Tutorials/Binary-Files-To-Database.aspx

|||

Hi,

Consider, you have query like

select files,filename,filesize,fileext from filesintable where id=1

that file on dar[0] as image datatype.

while (dar.Read())
{
bFile = (byte[])dar[0];
Response.AddHeader("Content-Disposition", "attachment; filename=" +dar[1].ToString());

switch (dar[3].ToString())
{
case "ask":
Response.ContentType = "video/x-ms-asf";
break;
case "avi":
Response.ContentType = "video/avi";
break;
case "doc":
Response.ContentType = "application/msword";
break;
case "zip":
Response.ContentType = "application/zip";
break;
case "xls":
Response.ContentType = "application/vnd.ms-excel";
break;
case "ppt":
Response.ContentType = "application/vnd.ms-powerpoint";
break;
case "gif":
Response.ContentType = "image/gif";
break;
case "jpg":
case "jpeg":
Response.ContentType = "image/jpeg";
break;
case "wav":
Response.ContentType = "audio/wav";
break;
case "mp3":
Response.ContentType = "audio/mpeg3";
break;
case "mpg":
case "mpeg":
Response.ContentType = "video/mpeg";
break;
case "rtf":
Response.ContentType = "application/rtf";
break;
case "htm":
case "html":
Response.ContentType = "text/html";
break;
case "asp":
Response.ContentType = "text/asp";
break;
case "pdf":
Response.ContentType = "application/pdf";
break;
default:
Response.ContentType = "application/octet-stream";
break;
}
Response.BinaryWrite(bFile);

}

It works fine.

Thursday, March 22, 2012

Download file that is stored in Sql Server database

Hi,
I have tried to implement file download option. I can download file which is stored in any folder. Code is...

string filepath = Request.Params["file"].ToString();
string filename = Path.GetFileName(filepath);
Response.Clear();
Response.ContentType = "image/gif";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.Flush();
Response.WriteFile(filepath);

This code is working fine. But now I am facing a problem. Files (not the path) are stored in database table. User can download file from the database. How can I do this? The file may be a .txt, .doc, .xls, .jpg or .gif.

Hi,|||

Hi,

first: get the data from DB

second: use the following code:

byte[] data = TheMethodToReadTheFieldFromDB();using (Stream st =new MemoryStream(data)){long dataLengthToRead = st.Length;Response.ContentType ="text/plain";//Or other you needResponse.AddHeader("Content-Disposition","attachment; filename=\"" + theFileName + "\"");while (dataLengthToRead > 0 && Response.IsClientConnected){Int32 lengthRead = st.Read(buffer, 0, blockSize);Response.OutputStream.Write(buffer, 0, lengthRead);Response.Flush();dataLengthToRead = dataLengthToRead - lengthRead;}Response.Flush();Response.Close();}Response.End();
|||

Thank your for your reply. It is working. I want to know one more thing. Can I zip a file before download? How?

Angshujit

|||

Hi,

If you wish to zip the file, you will need to load additional library to compress the file. You can search on the web to see if there is a library for your to use. Writing the compress algorithm will take you much efforts.

|||

Hi,

Thank you for your reply. I have found a library - ZipLib. Now it is working fine. But one problem is that every time in the time of download, it creates a zip file in the root folder. How can I delete this file?

Angshujit

|||

Hi angshujit,

You can use System.IO.File.Delete() method to delete the file. You need to make sure that the file has been downloaded to the client. Then you can delete the source file.

HTH. If this does not answer you question, please feel free to mark it as Not Answered and post your reply. Thanks!

|||

Hi Kevin,

Well, my "dilema" is similar. Basically instead of showing the content on the same page that made the request (let′s say on page 'A', where page 'A' has a button that says "select") I need to show my content on a new page. So far I have this:

void gv_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { String strResult ="", strExtension =""; String strDirectory, strFileName; GridView view = (GridView)sender; Guid __ID =new Guid(view.Rows[e.NewSelectedIndex].Cells[1].Text); Content c =new Content(Connection, __ID);// Byte[] btArray = c.GetFile(ref strResult,out strExtension);if (btArray !=null) { strDirectory ="ContentFiles"; strFileName = Page.Request.PhysicalApplicationPath; strFileName = strFileName + strDirectory;if (!System.IO.Directory.Exists(strFileName)) System.IO.Directory.CreateDirectory(strFileName); strFileName +="\\" +"content" + c.HumanNumber + strExtension;// System.IO.FileStream fs;if (!System.IO.File.Exists(strFileName)) fs = System.IO.File.Create(strFileName);else fs =new System.IO.FileStream(strFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);// System.IO.BinaryWriter writer =new System.IO.BinaryWriter(fs); writer.Write(btArray); writer.Flush(); writer.Close(); fs.Close(); Page.Response.Write("<script language=\"Javascript\">var win=window.open('" + strFileName +"',null,'width=510,height=255,top=250,left=250','true');</script>"); }//if (strResult.Contains("Null")) lblMessage.Text ="No file was returned. More information: " + strResult;else lblMessage.Text = strResult; }

So the file comes out of the database, into a folder and then has to be shown in a new window. It looks fine until I ran it and I get a JavaScript error saying: "Access Denied". I went on to change the permissions on the folder (mind you I am running this not on IIS but using the feature that VS2005 has) where the file gets saved, allowing "All" to read, yet nothing. Could somebody give me some pointers?

Thanks!

|||

Hi Kevin,

Well, my "dilema" is similar. Basically instead of showing the content on the same page that made the request (let′s say on page 'A', where page 'A' has a button that says "select") I need to show my content on a new page. So far I have this:

void gv_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { String strResult ="", strExtension =""; String strDirectory, strFileName; GridView view = (GridView)sender; Guid __ID =new Guid(view.Rows[e.NewSelectedIndex].Cells[1].Text); Content c =new Content(Connection, __ID);// Byte[] btArray = c.GetFile(ref strResult,out strExtension);if (btArray !=null) { strDirectory ="ContentFiles"; strFileName = Page.Request.PhysicalApplicationPath; strFileName = strFileName + strDirectory;if (!System.IO.Directory.Exists(strFileName)) System.IO.Directory.CreateDirectory(strFileName); strFileName +="\\" +"content" + c.HumanNumber + strExtension;// System.IO.FileStream fs;if (!System.IO.File.Exists(strFileName)) fs = System.IO.File.Create(strFileName);else fs =new System.IO.FileStream(strFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);// System.IO.BinaryWriter writer =new System.IO.BinaryWriter(fs); writer.Write(btArray); writer.Flush(); writer.Close(); fs.Close(); Page.Response.Write("<script language=\"Javascript\">var win=window.open('" + strFileName +"',null,'width=510,height=255,top=250,left=250','true');</script>"); }//if (strResult.Contains("Null")) lblMessage.Text ="No file was returned. More information: " + strResult;else lblMessage.Text = strResult; }

So the file comes out of the database, into a folder and then has to be shown in a new window. It looks fine until I ran it and I get a JavaScript error saying: "Access Denied". I went on to change the permissions on the folder (mind you I am running this not on IIS but using the feature that VS2005 has) where the file gets saved, allowing "All" to read, yet nothing. Could somebody give me some pointers?

Thanks!

|||

void gv_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { String strResult ="", strExtension =""; String strDirectory, strFileName, strUrl; GridView view = (GridView)sender; Guid __ID =new Guid(view.Rows[e.NewSelectedIndex].Cells[1].Text); Content c =new Content(Connection, __ID);// Byte[] btArray = c.GetFile(ref strResult,out strExtension);if (btArray !=null) { strDirectory = Page.Request.PhysicalApplicationPath +"ContentFiles\\";if (!System.IO.Directory.Exists(strDirectory)) System.IO.Directory.CreateDirectory(strDirectory); strFileName ="content" + c.HumanNumber + strExtension;// System.IO.FileStream fs;if (!System.IO.File.Exists(strDirectory + strFileName)) fs = System.IO.File.Create(strDirectory + strFileName);else fs =new System.IO.FileStream(strDirectory + strFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);// System.IO.BinaryWriter writer =new System.IO.BinaryWriter(fs); writer.Write(btArray); writer.Flush(); writer.Close(); fs.Close(); strUrl = Page.Request.Url.ToString(); strUrl = strUrl.Remove(strUrl.LastIndexOf('/'), strUrl.Length - strUrl.LastIndexOf('/')); strUrl +="/ContentFiles/"; Page.Response.Write("<script language=\"Javascript\">" +"var win=window.open('" + strUrl + strFileName +"',null,'width=510,height=255,top=250,left=250','true');" +"</script>"); }//if (strResult.Contains("Null")) lblMessage.Text ="No file was returned. More information: " + strResult;else lblMessage.Text = strResult; }
Hi all;

I've solved the problem. To solve it I had to store the file where the page was executing (Page.Request.PhysicalApplicationPath) and then surf it by the address of the current page (Page.Request.Url.ToString()) plus the name of the file. Unfortunatelly, since my web part will go inside a Sharepoint 2007, this aproach doesn't work because I can′t surf tohttp://sharepoint/SiteDirectory/mydepartment/Content%20%20Contents/ContentFiles/contentVD00005000.pdf. The file gets stored under C:\Inetpub\wwwroot\wss\VirtualDirectories\80\ContentFiles, now the million dollar questions is, how do you get to see the file? For those who want to see the code, it is above. If anybody can help me with popup windows and Sharepoint 2007 web parts that will be awesome.

Cheers,

|||

Kevin Yu - MSFT:

Hi angshujit,

You can use System.IO.File.Delete() method to delete the file. You need to make sure that the file has been downloaded to the client. Then you can delete the source file.

Just curious,

How would you make sure the file has been dowloaded to the client?

Thanks

/Kadji

Download Documents From Database

Does anyone have a code snippet in VBScript for how allow a user to save (or open) a document that has been stored in a database?

I have documents that are stored in an image column in a database. I have the code I need to upload documents from a user's browser. I'm not having any luck, however, figuring out how to let the user view or download the document that has been stored.

Regards,

Hugh ScottI'm no developer but found interesting code snippets from Planet SC (http://www.planet-source-code.com/).

HTH|||Sorry,

I had the code snippet right under my nose. This is VBScript:

<%
Set Conn = GetConnection
Set adoRS = Server.CreateObject("ADODB.Recordset")

'Open dynamic recordset, table Upload
adoRS.Open "SELECT * FROM tbl_Documents WHERE DocumentID = 1", Conn, 2, 2

sFileName = adoRS("SourceFileName")
sContentType = adoRS("ContentType")
sDataSize = adoRS("DataSize")

' clear the buffer
Response.Buffer = True
Response.Clear


' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & sFileName
' Response.AddHeader "Content-Length", sDataSize
Response.Charset = "UTF-8"
Response.ContentType = scontentType

' output the file to the browser
Response.BinaryWrite adoRS("Data")
Response.Flush


' tidy up
s.Close
Set s = Nothing

Function GetConnection()
dim Conn

Set Conn = CreateObject("ADODB.Connection")

Conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=iEIC;Data Source=MyServer"

Conn.Open

set GetConnection = Conn
end function
%>

Originally posted by hmscott
Does anyone have a code snippet in VBScript for how allow a user to save (or open) a document that has been stored in a database?

I have documents that are stored in an image column in a database. I have the code I need to upload documents from a user's browser. I'm not having any luck, however, figuring out how to let the user view or download the document that has been stored.

Regards,

Hugh Scott

Monday, March 19, 2012

doubt with sql and an store procedure

I'm working with the stored procedure editor of the Visual Web Developer, and I have this:
ALTER PROCEDURE dbo.ClasificacionSelectTodas
(
@.visibilidad bit = 1
)
AS
SET NOCOUNT ON
SELECT Clas_Id, Clas_Madre, Clas_Titulo, Clas_Descripcion, Clas_Prioridad, Clas_Visibilidad
FROM Clasificacion
WHERE (Clas_Visibilidad = @.visibilidad)
As you see, if I don't set any value to "@.visibilidad" it returns me the registries where visibilidad = 1
But what I want is that if I don't set any value to visibilidad, itturns to me all the registries. I was trying giving a default value tovisibilidad like "*" o "?", but it gives me an error.
Any idea?
ThanksStick out tongue [:P]
ALTER PROCEDURE dbo.ClasificacionSelectTodas
(
@.visibilidad bit = null
)
AS
SET NOCOUNT ON
SELECT Clas_Id, Clas_Madre, Clas_Titulo, Clas_Descripcion, Clas_Prioridad, Clas_Visibilidad
FROM Clasificacion
WHERE (Clas_Visibilidad = IsNull(@.visibilidad,Clas_Visibilidad))
This will compare Clas_Cisibilidad to the variable passed in (if not null) or with itself (which will always be true).|||Thanks douglas, it works greatStick out tongue [:P]
Congratulations for your book!
|||Glad it helped.
Also, I am actually working on a new book, tentatively titledStreamlined Web Forms Development. Should be out by ASP.NET 2.0 release, and will make a great stocking suffer<g>.|||I'm sure it will be highly interesting, I'll wait for it ;)

Sunday, March 11, 2012

double threading a procedure?

Over some time now, I've been developing a fairly hefty stored procedure, that does a lot of computations, and fairly few table lookups.

When I look at the performance on my server (a dual Xeon HT) I can see that it only uses 1 out of 4 possible "cpus" to work on the calculations, while the three others idle out, and was wondering if I can somehow force it to use max available CPU power?The optimizer is usually pretty good about choosing the execution plan. But it can be influenced.

Have you checked your MAXDOP setting? If it is set to 1, you can bump it up. But as with all advice, caveat executor!|||Me personally, I would have compartmentalized the sproc into smaller units of work, i.e., I would have made many sprocs instead of a mongo one.

To get the to run independantly, we have in the past set these many sprocs to be executed as jobs, then have a sproc that launches all of the jobs. The launch will be serial, but the execution would not be.

With one big sproc, everything is serial, and you are not pushing the CPU hard enough anyway. If you want additional ways to thread, you should set up your tables as partitioned views. then the CPU can thread out.

Other than that, with your methodology, there is no way where it will thread, or use additional cpus

MOO

double loop in stored procedure

Dear All,

Im working on a stored procedure that meant to mail out users some of their action items daily.

The procedure has a double loop, first the user ids and user email addresses are selected into a table, then the outer loop cycles through the user ids and selects relevant action items to another table. The inner loop then cycles through these action items and at the end of each outer loop a string is mailed out.

Problem is that as the outer loop selects the relevant items for a user, the table holding the action items basically gets filled with more and more records and the inner loop then adds every item in the table to the string that gets mailed out, ending up with more and more items going to all the users.

I have tried to delete all records from the actionItems table at the end of each outer loop after the content of the action Items are mailed out, however this seems to keep the actionItems table empty at all times.

Not sure if this description is clear enough but I cant see where Im going wrong in terms of approach.

Any ideas?I would suggest posting your SP here, so that we can check out what is going on in the T-SQL code.|||Any TSQL post that uses the word "loop" that frequently can't be good.|||Actually it's sorted, just added a variable that picks up the id of the last action item being added to the e-mail, then the count to add action items to the next e-mail starts from there + 1 AND also I had set this counter to 0 at the start as it would not start the loops while not initialised. Cheers|||Whatever. Continue merrilly down your path to the dark side...|||Actually it's sorted, just added a variable that picks up the id of the last action item being added to the e-mail, then the count to add action items to the next e-mail starts from there + 1 AND also I had set this counter to 0 at the start as it would not start the loops while not initialised. CheersHave you tried dropping charcoal briquettes or real cotton into fuming nitric acid?

-PatP

double lines with osql

Does anyone know how to eliminate the double lines that osql puts in your
output?
The help file says: "When running stored procedures, osql prints a blank
line between each set of results in a batch."
This may or may not be my problem. A very simple example:
osql -S[server_name] -U[logon_id] -P[pwd] -d[database] -w100 -otest.txt -Q"s
p_helptext tu_patient_insert" /h-1
The results gives an extra hard return after every line.
Any ideas would be appreciated!
TorryI don't see any way to circumvent it. If this is a single user process, you
could run 2 osql, one to dump the result from the sp into a global temp
table, the other to select from the global temp.
-oj
"Torry Slaton" <tslaton@.tcshealthcare.com> wrote in message
news:MdKdncmHg_DoWJ7fRVn-oQ@.megapath.net...
> Does anyone know how to eliminate the double lines that osql puts in your
> output?
> The help file says: "When running stored procedures, osql prints a blank
> line between each set of results in a batch."
> This may or may not be my problem. A very simple example:
> osql -S[server_name] -U[logon_id] -P[pwd] -d[database] -w100 -otest.txt -Q"s
> p_helptext tu_patient_insert" /h-1
> The results gives an extra hard return after every line.
> Any ideas would be appreciated!
> Torry
>

Friday, March 9, 2012

Double Byte to Single Byte

Most of the characters are stored in a Single byte but some Japanese
Characters requires Two Bytes to store Characters. Is there anyway to
store those characters in a Single byte? I am looking for the query or
any other tool. Is this possible with SQL Server or any other
programming Languages?
MadhivananAs there are potentially several thousand Kanji characters and only 256
possible values for a byte it really isn't possible to use 1 byte per
character.
Use the Unicode datatypes (NCHAR, NVARCHAR, NTEXT) to store multi-national
character sets. You can read about those in Books Online.
David Portas
SQL Server MVP
--

Dose sp_helptext loss something?

I am using sp_helptext to generate script of stored procedure. However someone said sp_helptext loss something if stored procedure is big. That means the script is not completed. Is it true?
Thanks
ZYTJust curious, why not use Enterprise Manager to right-click on the stored procedure, then go to All Tasks -> Generate SQL Script...?

Then you can punch the "preview" button and then the "copy" button to get the script onto your clipboard.|||Thanks for reply.

Because I need to create script from stored procedure.|||If you need to create a script from the stored procedure, why not use Enterprise Manager to right-click on the stored procedure, then go to All Tasks -> Generate SQL Script...?

Then you can punch the "preview" button and then the "copy" button to get the script onto your clipboard.|||sp_helptext only returns the first 4000 chars as i recall.|||Good Job, Jez...probably more constructive than a third post from me ;)|||check out this app I wrote if you want to generate scripts in an automated way:

http://www.codeplex.com/scriptdb

Dos commands within a stored procedure

Can I issue a dos command like
Cd\fred
Delete *.*
Thanks in advace for your assistance...use osql.
Mel|||Yes, though xp_cmdshell. Bu carefully consider the security implications.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:98BB887A-EDD1-4D08-966D-2938733502FD@.microsoft.com...
> Can I issue a dos command like
> Cd\fred
> Delete *.*
> Thanks in advace for your assistance...|||Hi Jim!
Don't forget that xp_cmdshell is disabled in SQL 2005 by default if that's
your platform. You'll need to enable it using the SQL Server Service Surface
Configuration Manager. And your DBA is gonna give you hell for doing so :-)
BTW, you would probably want to do a
del C:\fred\*.*
to chain the commands. And if you run a command shell like 4NT that aliases
commands like del, you may have to make it
*del C:\fred\*.*
Regards,
Jan
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OpneAAZWGHA.3328@.TK2MSFTNGP02.phx.gbl...
> Yes, though xp_cmdshell. Bu carefully consider the security implications.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
> news:98BB887A-EDD1-4D08-966D-2938733502FD@.microsoft.com...
>

Dos commands within a stored procedure

Can I issue a dos command like
Cd\fred
Delete *.*
Thanks in advace for your assistance...
use osql.
Mel
|||Yes, though xp_cmdshell. Bu carefully consider the security implications.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:98BB887A-EDD1-4D08-966D-2938733502FD@.microsoft.com...
> Can I issue a dos command like
> Cd\fred
> Delete *.*
> Thanks in advace for your assistance...
|||Hi Jim!
Don't forget that xp_cmdshell is disabled in SQL 2005 by default if that's
your platform. You'll need to enable it using the SQL Server Service Surface
Configuration Manager. And your DBA is gonna give you hell for doing so :-)
BTW, you would probably want to do a
del C:\fred\*.*
to chain the commands. And if you run a command shell like 4NT that aliases
commands like del, you may have to make it
*del C:\fred\*.*
Regards,
Jan
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OpneAAZWGHA.3328@.TK2MSFTNGP02.phx.gbl...
> Yes, though xp_cmdshell. Bu carefully consider the security implications.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
> news:98BB887A-EDD1-4D08-966D-2938733502FD@.microsoft.com...
>

Dos commands within a stored procedure

Can I issue a dos command like
Cd\fred
Delete *.*
Thanks in advace for your assistance...use osql.
Mel|||Yes, though xp_cmdshell. Bu carefully consider the security implications.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:98BB887A-EDD1-4D08-966D-2938733502FD@.microsoft.com...
> Can I issue a dos command like
> Cd\fred
> Delete *.*
> Thanks in advace for your assistance...|||Hi Jim!
Don't forget that xp_cmdshell is disabled in SQL 2005 by default if that's
your platform. You'll need to enable it using the SQL Server Service Surface
Configuration Manager. And your DBA is gonna give you hell for doing so :-)
BTW, you would probably want to do a
del C:\fred\*.*
to chain the commands. And if you run a command shell like 4NT that aliases
commands like del, you may have to make it
*del C:\fred\*.*
Regards,
Jan
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OpneAAZWGHA.3328@.TK2MSFTNGP02.phx.gbl...
> Yes, though xp_cmdshell. Bu carefully consider the security implications.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
> news:98BB887A-EDD1-4D08-966D-2938733502FD@.microsoft.com...
>> Can I issue a dos command like
>> Cd\fred
>> Delete *.*
>> Thanks in advace for your assistance...
>

Dont want stored procs to recompile..

How can I not have my stored procedures not to recompile whenever ?
The reason being is that when they recompile, they at times choose sub
optimal plans and causes a lot of pain to our applications. Is there any way
i can prevent sprocs not to recompile at a database or server level ? Using
SQL 2000
ThanksUnless you put WITH RECOMPILE option when you create the stored
procedure. The auto-recompile only happens under two conditions:
1) The first time a stored procedure is run after Microsoft=AE SQL
Server=99 2000 is restarted.
2) It also occurs if an underlying table used by the stored procedure
changes.
And it is mainly for optimization purpose (to keep the executation plan
efficient and up to date).
I don't think you can stop the auto-recompile behaviour. But you can
influence the executation plan by adding HINTS in your stored
procedure.
Mel|||Another option is to upgrade to 2005 where you can associate a plan with it
or to use a hint that allows you to optimize for a specific value.
Andrew J. Kelly SQL MVP
"Hassan" <Hassan@.hotmail.com> wrote in message
news:%23rtKRwLYGHA.5004@.TK2MSFTNGP02.phx.gbl...
> How can I not have my stored procedures not to recompile whenever ?
> The reason being is that when they recompile, they at times choose sub
> optimal plans and causes a lot of pain to our applications. Is there any
> way i can prevent sprocs not to recompile at a database or server level ?
> Using SQL 2000
> Thanks
>|||Hi Hassan
Although you can force a procedure to recompile, you can't stop it from reco
mpiling when it thinks it needs to. All you can do is try to reduce the numb
er of situations where it wants to recompile.
There are many situations that will cause a procedure to recompile.
Take a look at these two KB articles:
How to identify the cause of recompilation in an SP:Recompile event
http://support.microsoft.com/kb/308737
Troubleshooting stored procedure recompilation
http://support.microsoft.com/kb/243586/
And look at this Whitepaper, which is directed to SQL Server 2005, but much
of it is also useful for SQL 2000:
Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server 2005
http://www.microsoft.com/technet/pr...005/recomp.mspx
--
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"Hassan" <Hassan@.hotmail.com> wrote in message news:%23rtKRwLYGHA.5004@.TK2MSFTNGP02.phx.gbl.
.
> How can I not have my stored procedures not to recompile whenever ?
>
> The reason being is that when they recompile, they at times choose sub
> optimal plans and causes a lot of pain to our applications. Is there any w
ay
> i can prevent sprocs not to recompile at a database or server level ? Usin
g
> SQL 2000
>
> Thanks
>
>

Dont want stored procs to recompile..

How can I not have my stored procedures not to recompile whenever ?
The reason being is that when they recompile, they at times choose sub
optimal plans and causes a lot of pain to our applications. Is there any way
i can prevent sprocs not to recompile at a database or server level ? Using
SQL 2000
ThanksUnless you put WITH RECOMPILE option when you create the stored
procedure. The auto-recompile only happens under two conditions:
1) The first time a stored procedure is run after Microsoft=AE SQL
Server=99 2000 is restarted.
2) It also occurs if an underlying table used by the stored procedure
changes.
And it is mainly for optimization purpose (to keep the executation plan
efficient and up to date).
I don't think you can stop the auto-recompile behaviour. But you can
influence the executation plan by adding HINTS in your stored
procedure.
Mel|||Another option is to upgrade to 2005 where you can associate a plan with it
or to use a hint that allows you to optimize for a specific value.
--
Andrew J. Kelly SQL MVP
"Hassan" <Hassan@.hotmail.com> wrote in message
news:%23rtKRwLYGHA.5004@.TK2MSFTNGP02.phx.gbl...
> How can I not have my stored procedures not to recompile whenever ?
> The reason being is that when they recompile, they at times choose sub
> optimal plans and causes a lot of pain to our applications. Is there any
> way i can prevent sprocs not to recompile at a database or server level ?
> Using SQL 2000
> Thanks
>|||This is a multi-part message in MIME format.
--=_NextPart_000_038B_01C66093.387A0E60
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi Hassan
Although you can force a procedure to recompile, you can't stop it from =recompiling when it thinks it needs to. All you can do is try to reduce =the number of situations where it wants to recompile.
There are many situations that will cause a procedure to recompile.
Take a look at these two KB articles:
How to identify the cause of recompilation in an SP:Recompile event
http://support.microsoft.com/kb/308737=20
Troubleshooting stored procedure recompilation
http://support.microsoft.com/kb/243586/
And look at this Whitepaper, which is directed to SQL Server 2005, but =much of it is also useful for SQL 2000:
Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server =2005 http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx
-- HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"Hassan" <Hassan@.hotmail.com> wrote in message =news:%23rtKRwLYGHA.5004@.TK2MSFTNGP02.phx.gbl...
> How can I not have my stored procedures not to recompile whenever ?
> > The reason being is that when they recompile, they at times choose sub =
> optimal plans and causes a lot of pain to our applications. Is there =any way > i can prevent sprocs not to recompile at a database or server level ? =Using > SQL 2000
> > Thanks > >
--=_NextPart_000_038B_01C66093.387A0E60
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Hi Hassan
Although you can force a procedure to =recompile, you can't stop it from recompiling when it thinks it needs to. All you =can do is try to reduce the number of situations where it wants to recompile.
There are many situations that will =cause a procedure to recompile.
Take a look at these two KB =articles:
How to identify the cause of =recompilation in an SP:Recompile event

Troubleshooting stored =procedure recompilation
http://support.microsoft.com/kb/243586/
And look at this Whitepaper, which is =directed to SQL Server 2005, but much of it is also useful for SQL =2000:
Batch Compilation, Recompilation, and =Plan Caching Issues in SQL Server 2005
http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.msp=x-- HTHKalen Delaney, SQL Server =MVPwww.solidqualitylearning.com
"Hassan" =wrote in message news:%23rtKRwLYGHA.5004@.TK2MSFTNGP02.phx.gbl...> =How can I not have my stored procedures not to recompile whenever ?> > =The reason being is that when they recompile, they at times choose sub => optimal plans and causes a lot of pain to our applications. Is there any =way > i can prevent sprocs not to recompile at a database or server =level ? Using > SQL 2000> > Thanks > >

--=_NextPart_000_038B_01C66093.387A0E60--

Sunday, February 26, 2012

Domains

What is the best way to move Views and Stored Procedures from Dev to Prod?
Is DTS a good option. Thankshi niles,
Go to Enterprise manager. Right click on the database. click on "all
tasks" . click on "generate sql script". click on "show all". Click on "all
views" and "all stored procedures", this will generate a script file with
DDL commands. You can run this file on the destination database/server
through query analyzer.
Vishal Parkar
vgparkar@.yahoo.co.in|||Thanks, works beautifully!