Showing posts with label vs2005. Show all posts
Showing posts with label vs2005. Show all posts

Monday, March 12, 2012

How to set SQLCommand timeout for SqlDataSource for ASP.NET 2.0?

With VS2005, there is a new component SqlDataSource,

<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>

Then you can assign SP and bind datasource to a get data for this component in .NET code:

SqlDataSource1.SelectCommand = "spName"
SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
SqlDataSource1.ConnectionString = Comm.connString

There is no way to set sqlcommand timeout for this stored procedure like SqlClient.SqlCommand. How can I do this?

Inside the SqlDataSource1_Selecting event, you get access to the sqlcommand object via e.command. You can set the commandtimeout on it there, like:

e.Command.CommandTimeout=300

|||

Thanks for your reply. But when is the event Selecting fired? Is it fired automatically when binding to data source?

|||

Hi KentZhou,

The sqldatasource.selecting event happends right before your perform a data retrieval opteration(where you execute your select command).You can refer to the msdn explaination:

msdn:

Occurs before a data retrieval operation.

Handle theSelecting event to perform additional initialization operations that are specific to your application, to validate the values of parameters, or to change the parameter values before theSqlDataSource control performs the select operation. The select arguments are available from theSqlDataSourceSelectingEventArgs object that is associated with the event.

Hope my suggestion helps

|||

The short answer is "Yes".

It fires any time that you do a databind.

The long answer as described above, it actually happens any time that the SqlDatasource is about to go and execute your select command. This is normally done through a databinding operation (Either implied or programmatically triggered), however it can also be triggered if you call the select method on the SqlDatasource directly.

How to set SQL Server and VS default folder paths?

Ive just installed VS2005 Pro and SQL Server Developer edition.

Now I want to set the default paths for project, templates, settings. But I want for both VS and SQL files.

For example, right now the default folders for SQL Studio are:

.\My Documents\SQL Server Management Studio\Projects

.\My Documents\SQL Server Management Studio\Settings

.\My Documents\SQL Server Management Studio\Templates

.\My Documents\SQL Server Management Studio\Backup Files

... and so on.

For VS Studio:

.\My Documents\Visual Studio 2005\Projects

.\My Documents\Visual Studio 2005\Templates

.\My Documents\Visual Studio 2005\Code Snippets

... and so on.

I would like for all sub-folders(from SQL Server and VS) to be in one same folder(Development), for example:

.\My Documents\Development\Projects

.\My Documents\Development\Settings

.\My Documents\Development\Templates

.\My Documents\Development\Backup Files

.\My Documents\Development\Code Snippets

... and so on.

I have tried changing in each application′s options the default path for each one, pointing to each folder I listed above.

My problem is that both VS and SQL Server still keeps creating folders in the old locations, for example: ".\My Documents\SQL Server Management Studio\Projects". This example happens when I create a new query, and try to save it, it automatically creates that folder.

It only works for a few of them, like the settings folder. Ive managed to create a single folder for SQL and VS setting files.

Is there a way I can join both Application folders? I want to keep both projects files in one folder, both setting files in one folder, and so on...

I hope I explained well my situation.

Thanks!

In VS 2005 you can change default directories by going to Tools >> Options menu then selecting Projects and Solutions.

In SQL Management Studio I believe it opens your last known file path you opened.

Justin King
|||SQL Server Managemetn Studio does not retain your file location between sessions. As far as I can tell there is no way to change this and the MS help facility neither confirms nor denies this assumption.
|||

So its not possible to change that?

Ive changed all places in the registry (all the keys I think might change that)
Still it creates the folders. Are there other places I can change that?

Thanks for the help.