Showing posts with label net. Show all posts
Showing posts with label net. Show all posts

Wednesday, March 28, 2012

How to format a date field in select query

Is it possible to format the date field create_date (mm/dd/yyyy or mm/dd/yy)
I use the following query in stored proc. will be called in the asp.net page for population the datagrid.

select id, name, create_date from actionstable;

Please help, Thank you.You can use the SQL CONVERT() function, to convert the date to an nvarchar(), or better, format the date in the presentation layer, in the datagrid itself. In the DataFormatString of the DataGrid's column that will contain the date, use 0:d

Monday, March 26, 2012

How to fix SQLExpress "attempt to attach an auto-named database" e

I'm authoring a .net webservice that connects to a SQLExpress database in the
same project. When the code calls the database the following exception is
thrown:
"An attempt to attach an auto-named database for file
C:\[...]\App_Data\App_Data\MyDatabase.mdf failed. A database with the same
name exists, or specified file cannot be opened, or it is located on UNC
share."
I've read all the online help I can find but none of the suggestions work.
* I've deleted the SQLExpress folder in my ApplicationData
* I've made sure to enable user instances in the server and RECONFIGURE
* I've restarted the service
* I've ensured that ASPNET and NETWORK SERVICE has rights to the APP_DATA
folder.
Nothing changes. What is the cause of this issue' How can I fix it'
Thanks,
JasonSolved.
It took finally writing this post to see that the rendered connection string
renders "APP_DATA" twice.
This is how the project defaults - I didn't do that. Screw them.
Jason
"Jason" wrote:
> I'm authoring a .net webservice that connects to a SQLExpress database in the
> same project. When the code calls the database the following exception is
> thrown:
> "An attempt to attach an auto-named database for file
> C:\[...]\App_Data\App_Data\MyDatabase.mdf failed. A database with the same
> name exists, or specified file cannot be opened, or it is located on UNC
> share."
> I've read all the online help I can find but none of the suggestions work.
> * I've deleted the SQLExpress folder in my ApplicationData
> * I've made sure to enable user instances in the server and RECONFIGURE
> * I've restarted the service
> * I've ensured that ASPNET and NETWORK SERVICE has rights to the APP_DATA
> folder.
> Nothing changes. What is the cause of this issue' How can I fix it'
> Thanks,
> Jason|||Congratulations!
Have a great day!
Charles Wang
Microsoft Online Community Support|||But it still doesn't work right. After the change, it will not have that
error in run-time, but now it won't work in design-time. The DataSet
visualizer can't find the datasource from the given connectionString.
This is using the Application project template for WebService and not the
Website template. That may be part of the problem.
Jason
"Charles Wang[MSFT]" wrote:
> Congratulations!
> Have a great day!
> Charles Wang
> Microsoft Online Community Support
>|||Hi Jason,
Thanks for your response.
I recommend that you try to connect the SQL Server Express on other clients
via SQL Query Analyzer or other SQL client tools. If you manage to access
the server, this issue is most likely caused by some settings in your
Webservice IDE (vs.net 2005?). You can post this issue to .net public
community for best support.
Also, for now, I recommend that you check your connection string, by
default the SQLExpress instance name should be set to "<server
name>\SQLEXPRESS".
You may want these references:
http://blog.davebouwman.net/2006/03/27/SQLExpressConnectionProblems.aspx
http://msdn.microsoft.com/vbrun/vbfusion/usingsqlexpress/
http://www.connectionstrings.com/
Charles Wang
Microsoft Online Community Support|||Hi ,
Just checking in to see if the suggestions were helpful. Please let us know
if you would like further assistance.
Have a great day!
Charles Wang
Microsoft Online Community Support|||Charles,
Thanks, but no. Those suggestions seem to address a different issue. I
think what's happening here is that when using the non-website project
template for ASP.Net Webservice (downloaded from Microsoft's site) the
connection string contains an extra "APP_DATA" directory literal.
At design time, this is the correct setting and the dataset designers can
find and connect to the database correctly, but at runtime the "APP_DATA"
literal is /extra/ because the "|DataDirectory|" placeholder is resolved
differently to already include the APP_DATA folder.
I'm posting these findings to save others from frustration, but I've in fact
changed direction.
Jason
"Charles Wang[MSFT]" wrote:
> Hi ,
> Just checking in to see if the suggestions were helpful. Please let us know
> if you would like further assistance.
> Have a great day!
> Charles Wang
> Microsoft Online Community Support
>|||Hi Jason,
Appreciate your posting here for having others benefit from this issue.
My former reply may not understand your issue clearly. I thought it was
just a normal SQL Server break/fix issue on connection.
This issue is most likely a .net development issue.I recommend that you
post this issue to public .net newsgroups for best professional support.
If you also want to get support on this newsgroup, I would like to get a
simple project example from you so that I can try to reproduce this issue
for further research.
Sincerely yours,
Charles Wang
Microsoft Online Community Support|||I just had the same problem. I noticed that Permissions on APP_DATA
were not being inherited by the .mdf and .ldf files. Made sure ASPNET
had permission to folder then changed to inherit permissions and all
works OK. Don't know security issues but this is a development site so
don't care.

How to fix SQLExpress "attempt to attach an auto-named database" e

I'm authoring a .net webservice that connects to a SQLExpress database in th
e
same project. When the code calls the database the following exception is
thrown:
"An attempt to attach an auto-named database for file
C:\[...]\App_Data\App_Data\MyDatabase.mdf failed. A database with the sa
me
name exists, or specified file cannot be opened, or it is located on UNC
share."
I've read all the online help I can find but none of the suggestions work.
* I've deleted the SQLExpress folder in my ApplicationData
* I've made sure to enable user instances in the server and RECONFIGURE
* I've restarted the service
* I've ensured that ASPNET and NETWORK SERVICE has rights to the APP_DATA
folder.
Nothing changes. What is the cause of this issue' How can I fix it'
Thanks,
JasonSolved.
It took finally writing this post to see that the rendered connection string
renders "APP_DATA" twice.
This is how the project defaults - I didn't do that. Screw them.
Jason
"Jason" wrote:

> I'm authoring a .net webservice that connects to a SQLExpress database in
the
> same project. When the code calls the database the following exception is
> thrown:
> "An attempt to attach an auto-named database for file
> C:\[...]\App_Data\App_Data\MyDatabase.mdf failed. A database with the
same
> name exists, or specified file cannot be opened, or it is located on UNC
> share."
> I've read all the online help I can find but none of the suggestions work.
> * I've deleted the SQLExpress folder in my ApplicationData
> * I've made sure to enable user instances in the server and RECONFIGURE
> * I've restarted the service
> * I've ensured that ASPNET and NETWORK SERVICE has rights to the APP_DATA
> folder.
> Nothing changes. What is the cause of this issue' How can I fix it'
> Thanks,
> Jason|||Congratulations!
Have a great day!
Charles Wang
Microsoft Online Community Support

How to fire off a report and save it as pdf...

Using vb.net, does anyone know or has anyone fired off a sql report, save it as PDF to a defined path?

I am knew to sql reporting services and the help files are not very helpfile.

Any sample code would be helpful.

Thanks

Hello,

Have a look at the sample code on this page:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspx

Specify the export format you want (in your case "PDF") as a parameter to the Render method.

-Chris

|||

I looked at the sample code, how ever, not sure where the references are to things like

"ReportExecutionService" and some of the other objects.

WHich .net items do I need to import?

Daryl

|||In your project you need add a web reference to the reportexecution service. this will create a proxy class that you an instantiate in code to call the web service|||does it matter that I am NOT building a web application? Building a Desktop vb.net exe.|||no it doesn't matter|||

I cannot find this reference. I looked in windows and system...

|||Right-click your project and select "Add Web Reference"|||

Hi Adam,

The post and the replies are really useful. Thanks a lot for the help...

Adam, the URL "http://localhost/reportserver/reportexecution2005.asmx" needs to be a working one or are we giving a dummy value?

Thanks in advance for the help....

Sudhiiiii...

|||Replace "localhost" with the name of your reports server.|||

Hi,

First of all thanks for the reply.

I tried the above stated method and the URL for my system was "http://localhost/reportserver$sqlserver/reportexecution2005.asmx".

As i'm developing a Windows application solution, i hasn't deployed any of my reports in the specified URL or any other.

I tried to add the URL as a Web reference its saying the URL doesnot contain any web service.

I tried to browse the URL manually, its saying that there is an authentication problem, and user "systemname\ASPNet" is unable to connect to the Database.I went to Sql server and given all the rights to 'aspnet" user , which was a normal user previously.In IIS i tried giving anonyous rights as well as windows integrated user for the virtual directory .My DB is having full rights, and working on integrated user while using the forms.

still the problem persists.

1) is the problem in SQL server or IIS or windows...?

2)Does this has any relation to 'ASP.Net state service' service in windows

3) will me publishing the reorts in iis server will solve the issue. I should have tried this but i'm a too newbie in this and i need to search for how to do that...

Please do help...... Thanks in advance......

Sudhiiii....

|||

Sudeesh,

If you are developing a windows application then you should use the ReportViewer control. This can be used in one of 2 modes:

local mode: the report files are saved as RDLC and stored in the application directory (no report server required)

server mode: where the control connects to a report server and displays shared reports. For this reports need to deployed tot he server.

|||

Hi Adam,

Thanks a lot for the reply...

I should have told my problem in detail...

Let me do that now..

I'm creating a windows application With Vb2005 and Sql 2005 express editions.
The basic point is to create 5 reports from the data in sql tables, each one having several subreports. These reports have to be exported to Excel as there was a VBA application on Excel previously.Currently I'm able to manually save each report as an individual file and later open five excel files move/copy them into one file and then save the excel.I want to automate the task using code such that for the end user it should be like, one button pressed and five reports are saved to excel file... The issue is that i'm able to save at least a report to an excel file manually only, not using code.

Once i'm able to save one report by code we can bundle all of them into one workbook.

To view the report I'm using Reportviewer control but i'm not able to save it.

I hope i made it clear....

Sudhiiiii...

sql

Friday, March 23, 2012

How to fire off a report and save it as pdf...

Using vb.net, does anyone know or has anyone fired off a sql report, save it as PDF to a defined path?

I am knew to sql reporting services and the help files are not very helpfile.

Any sample code would be helpful.

Thanks

Hello,

Have a look at the sample code on this page:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspx

Specify the export format you want (in your case "PDF") as a parameter to the Render method.

-Chris

|||

I looked at the sample code, how ever, not sure where the references are to things like

"ReportExecutionService" and some of the other objects.

WHich .net items do I need to import?

Daryl

|||In your project you need add a web reference to the reportexecution service. this will create a proxy class that you an instantiate in code to call the web service|||does it matter that I am NOT building a web application? Building a Desktop vb.net exe.|||no it doesn't matter|||

I cannot find this reference. I looked in windows and system...

|||

Right-click your project and select "Add Web Reference"

How to fire off a report and save it as pdf...

Using vb.net, does anyone know or has anyone fired off a sql report, save it as PDF to a defined path?

I am knew to sql reporting services and the help files are not very helpfile.

Any sample code would be helpful.

Thanks

Hello,

Have a look at the sample code on this page:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspx

Specify the export format you want (in your case "PDF") as a parameter to the Render method.

-Chris

|||

I looked at the sample code, how ever, not sure where the references are to things like

"ReportExecutionService" and some of the other objects.

WHich .net items do I need to import?

Daryl

|||In your project you need add a web reference to the reportexecution service. this will create a proxy class that you an instantiate in code to call the web service|||does it matter that I am NOT building a web application? Building a Desktop vb.net exe.|||no it doesn't matter|||

I cannot find this reference. I looked in windows and system...

|||Right-click your project and select "Add Web Reference"|||

Hi Adam,

The post and the replies are really useful. Thanks a lot for the help...

Adam, the URL "http://localhost/reportserver/reportexecution2005.asmx" needs to be a working one or are we giving a dummy value?

Thanks in advance for the help....

Sudhiiiii...

|||Replace "localhost" with the name of your reports server.|||

Hi,

First of all thanks for the reply.

I tried the above stated method and the URL for my system was "http://localhost/reportserver$sqlserver/reportexecution2005.asmx".

As i'm developing a Windows application solution, i hasn't deployed any of my reports in the specified URL or any other.

I tried to add the URL as a Web reference its saying the URL doesnot contain any web service.

I tried to browse the URL manually, its saying that there is an authentication problem, and user "systemname\ASPNet" is unable to connect to the Database.I went to Sql server and given all the rights to 'aspnet" user , which was a normal user previously.In IIS i tried giving anonyous rights as well as windows integrated user for the virtual directory .My DB is having full rights, and working on integrated user while using the forms.

still the problem persists.

1) is the problem in SQL server or IIS or windows...?

2)Does this has any relation to 'ASP.Net state service' service in windows

3) will me publishing the reorts in iis server will solve the issue. I should have tried this but i'm a too newbie in this and i need to search for how to do that...

Please do help...... Thanks in advance......

Sudhiiii....

|||

Sudeesh,

If you are developing a windows application then you should use the ReportViewer control. This can be used in one of 2 modes:

local mode: the report files are saved as RDLC and stored in the application directory (no report server required)

server mode: where the control connects to a report server and displays shared reports. For this reports need to deployed tot he server.

|||

Hi Adam,

Thanks a lot for the reply...

I should have told my problem in detail...

Let me do that now..

I'm creating a windows application With Vb2005 and Sql 2005 express editions.
The basic point is to create 5 reports from the data in sql tables, each one having several subreports. These reports have to be exported to Excel as there was a VBA application on Excel previously.Currently I'm able to manually save each report as an individual file and later open five excel files move/copy them into one file and then save the excel.I want to automate the task using code such that for the end user it should be like, one button pressed and five reports are saved to excel file... The issue is that i'm able to save at least a report to an excel file manually only, not using code.

Once i'm able to save one report by code we can bundle all of them into one workbook.

To view the report I'm using Reportviewer control but i'm not able to save it.

I hope i made it clear....

Sudhiiiii...

How to fire off a report and save it as pdf...

Using vb.net, does anyone know or has anyone fired off a sql report, save it as PDF to a defined path?

I am knew to sql reporting services and the help files are not very helpfile.

Any sample code would be helpful.

Thanks

Hello,

Have a look at the sample code on this page:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspx

Specify the export format you want (in your case "PDF") as a parameter to the Render method.

-Chris

|||

I looked at the sample code, how ever, not sure where the references are to things like

"ReportExecutionService" and some of the other objects.

WHich .net items do I need to import?

Daryl

|||In your project you need add a web reference to the reportexecution service. this will create a proxy class that you an instantiate in code to call the web service|||does it matter that I am NOT building a web application? Building a Desktop vb.net exe.|||no it doesn't matter|||

I cannot find this reference. I looked in windows and system...

|||Right-click your project and select "Add Web Reference"|||

Hi Adam,

The post and the replies are really useful. Thanks a lot for the help...

Adam, the URL "http://localhost/reportserver/reportexecution2005.asmx" needs to be a working one or are we giving a dummy value?

Thanks in advance for the help....

Sudhiiiii...

|||Replace "localhost" with the name of your reports server.|||

Hi,

First of all thanks for the reply.

I tried the above stated method and the URL for my system was "http://localhost/reportserver$sqlserver/reportexecution2005.asmx".

As i'm developing a Windows application solution, i hasn't deployed any of my reports in the specified URL or any other.

I tried to add the URL as a Web reference its saying the URL doesnot contain any web service.

I tried to browse the URL manually, its saying that there is an authentication problem, and user "systemname\ASPNet" is unable to connect to the Database.I went to Sql server and given all the rights to 'aspnet" user , which was a normal user previously.In IIS i tried giving anonyous rights as well as windows integrated user for the virtual directory .My DB is having full rights, and working on integrated user while using the forms.

still the problem persists.

1) is the problem in SQL server or IIS or windows...?

2)Does this has any relation to 'ASP.Net state service' service in windows

3) will me publishing the reorts in iis server will solve the issue. I should have tried this but i'm a too newbie in this and i need to search for how to do that...

Please do help...... Thanks in advance......

Sudhiiii....

|||

Sudeesh,

If you are developing a windows application then you should use the ReportViewer control. This can be used in one of 2 modes:

local mode: the report files are saved as RDLC and stored in the application directory (no report server required)

server mode: where the control connects to a report server and displays shared reports. For this reports need to deployed tot he server.

|||

Hi Adam,

Thanks a lot for the reply...

I should have told my problem in detail...

Let me do that now..

I'm creating a windows application With Vb2005 and Sql 2005 express editions.
The basic point is to create 5 reports from the data in sql tables, each one having several subreports. These reports have to be exported to Excel as there was a VBA application on Excel previously.Currently I'm able to manually save each report as an individual file and later open five excel files move/copy them into one file and then save the excel.I want to automate the task using code such that for the end user it should be like, one button pressed and five reports are saved to excel file... The issue is that i'm able to save at least a report to an excel file manually only, not using code.

Once i'm able to save one report by code we can bundle all of them into one workbook.

To view the report I'm using Reportviewer control but i'm not able to save it.

I hope i made it clear....

Sudhiiiii...

Monday, March 19, 2012

How to find Sql Server properties programatically

I am writing a program in .Net to retrieve properties of Sql Server.
How can I find the following properties without querying the database:

1. Replication enabled
2. Default language
3. Processors and threads running.

Thanks,
verveYou're probably looking for SQLDMO, which is a COM interface to MSSQL -
see Books Online for the details.

1. You can use the SQLDMO Replication object to enumerate replicated
databases, individual publications and articles etc.

2. Use the SQLServer.Language property

3. I'm not sure exactly what you want, but WMI might be a better option
for hardware and OS information. If by "threads" you really mean SQL
Server processes, then you can use the SQLServer.EnumProcesses method

In many cases, SQLDMO executes TSQL commands behind the scenes, so you
still need an authenticated connection to the server (and possibly a
user mapping in individual databases) to use it.

Simon|||Hi,
Thanks for the prompt reply but can also tell me which classes I should
be querying in WMI or which interface?

Thanks in advance :)
Verve|||The full WMI reference is on MSDN, but the TechNet scripting library
might be a faster way to get started:

http://www.microsoft.com/technet/sc...c/hwbavb03.mspx
http://www.microsoft.com/technet/sc...d/pcthvb07.mspx

Simon

Friday, February 24, 2012

How to find cause of time-outs?

I am getting some .NET application exceptions saying the request to SQL
Server 2005 timed out. It is not always the same procedures that time out.
It is also very intermittent. How can I find out which SQL tasks are
running slow or to blame? I don't know where to look, what to log, etc.
.NET can't tell me more from its end.You could start by taking a look at this article on how to monitor
blocking.
http://support.microsoft.com/default.aspx?scid=kb;en-us;271509.

How to find cause of time-outs?

I am getting some .NET application exceptions saying the request to SQL
Server 2005 timed out. It is not always the same procedures that time out.
It is also very intermittent. How can I find out which SQL tasks are
running slow or to blame? I don't know where to look, what to log, etc.
.NET can't tell me more from its end.You could start by taking a look at this article on how to monitor
blocking.
http://support.microsoft.com/defaul...b;en-us;271509.

Sunday, February 19, 2012

How to filter a report using an asp.net page

Hi,
I need to filter a single .rdl page in accordance with an option chosen from an asp.net page.
I know how to filter a report within the reporting page. But how can I do the filtering from an asp.net page? For example I have a Report1.rdl that prints out all the locations. I need the same report1.rdl page to print out only for a certain location based on the option I chose from the asp.net page. My asp.net page has 3 buttons. One to for all locations, another for location1, and the other one for location2. Please help. Thanks

1. Add a parameter to the report for location.

2. Modify your SQL code to account for that parameter, ie. WHERE Location = @.Location.

3. In Visual Studio, pass the location parameter value based upon the option chosen.

|||

GregSQL wrote:

1. Add a parameter to the report for location.

2. Modify your SQL code to account for that parameter, ie. WHERE Location = @.Location.

3. In Visual Studio, pass the location parameter value based upon the option chosen.

Thanks Greg. I got 1 and 2 working. Now how do I make the 3rd part? How do I call the parameters from an asp.net page to show the report in a browser? Thanks again for your help.
|||

Code Snippet

Dim param AsNew Microsoft.Reporting.WebForms.ReportParameter

Dim paramarr(0) As Microsoft.Reporting.WebForms.ReportParameter

param = New Microsoft.Reporting.WebForms.ReportParameter("myParameter", DropDownList1.SelectedValue.ToString())

paramarr(0) = param

ReportViewer1.ServerReport.SetParameters(paramarr)

This would set the report parameter myParameter to the selected value of DropDownList1. Remember that the parameterarray's starting index is zero...that typically leads me to off by one errors.

Oh and I was somewhat assuming that you already knew how to use a report viewer component in .NET to display a report in an internet browser. If not, let me know.