Showing posts with label built. Show all posts
Showing posts with label built. Show all posts

Wednesday, March 28, 2012

How do I access a SQL view in VB.Net?

I'm able to access my stored procedures just fine, but I can't query/show a view that I'd built in SQL Server. Any suggestions on how would be welcome.

Sample Stored Procedure reference, and I just want to reference a view now:


' Connect to the Database
Dim MyConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("myConnectionString"))
' Establish the set of data commands and a database connection that are used to fill the dataset
Dim MyCommand As New SqlCommand("vw_Mast_PW_Accounts", MyConn)

MyCommand.CommandType = CommandType.StoredProcedure

MyConn.Open()

dgMyGrid.DataSource = MyCommand.ExecuteReader
dgMyGrid.DataBind()

MyConn.Close()

I might be mistaken here, but a view is treated pretty much like a table. So if you want to return data from a view, query against it as if it were a table: SELECT * FROM vw_myView WHERE ...

You'll need to make sure your web app has permissions to query the view and, I think, any underlying tables (though I might be wrong on that last point).|||That's great, but do is there a way to do it without using SQL but simply referencing it as I would a stored procedure (i.e., just the name)?

Thank you,
Brent|||I don't believe so, for that same reason that you couldn't do that with a table.

Youcould create a stored procedure that returned data from your view, if you really needed that functionality...|||I gave up and built the stored procedure to access that view. Thank you for the suggestion!

Brent

Sunday, February 19, 2012

How can I track the queries being issued against my sql server 2000 instance?

I have an ASP.NET app built on top of SQL Server 2000. My app is running slowly and I think I'm issuing too many queries to the database.

How can I track the queries, and when they are being issued, against my sql server 2000 instance? Is there a tool to view the queries, or is it all in a log file somewhere?

This will help me tune my ASP.NET caching strategy.

Any help is greatly appreciated!

Franco

Use SQL Server Profiler|||Choose: SQL Server, Tools, SQL Profile, File, New, Trace, Choose Server...

On the filters tab of the new window you see you can choose various filters. These include database name, application name, NT UserName, there are many to choose from.

SQL Profiler is an amazing tool for seeing whats happening "under the hood" I suggest you really read up on it in SQL Books Online as its extremely powerful.

Keep us all up to date with how you are getting on.

hth

Pace
|||Fantastic... just what I needed. Thanks!

How can I track the queries being issued against my sql server 2000 instance?

I have an ASP.NET app built on top of SQL Server 2000. My app is running slowly and I think I'm issuing too many queries to the database.

How can I track the queries, and when they are being issued, against my sql server 2000 instance? Is there a tool to view the queries, or is it all in a log file somewhere?

This will help me tune my ASP.NET caching strategy.

Any help is greatly appreciated!

Franco

Use SQL Server Profiler|||Choose: SQL Server, Tools, SQL Profile, File, New, Trace, Choose Server...

On the filters tab of the new window you see you can choose various filters. These include database name, application name, NT UserName, there are many to choose from.

SQL Profiler is an amazing tool for seeing whats happening "under the hood" I suggest you really read up on it in SQL Books Online as its extremely powerful.

Keep us all up to date with how you are getting on.

hth

Pace
|||Fantastic... just what I needed. Thanks!