Using VS 2013 (VB) and SQL Server 2012.
I execute a stored procedure to populate a gridview using linq.
Dim db As New GMConnectionDataContext
Dim gasHedges = db.GasHedges_create2ndMonth.ToList
The stored procedure returns a result set and has been working fine as in it returns the expected result and the gridview displays as desired.
I added some data to my SQL table and loaded the web page and the new data does not show. IF I execute the stored procedure in SQL Server the new data shows. If I execute the stored procedure in VS the new data shows.
Now the weird bit. If I delete the reference to the stored procedure from the .dbml file then re-add it the new data shows when the page is loaded. I know that when using this file if I add columns to a table then I need to delete it and re-add the table to the .dbml file.
Surely the same isn't the case with stored procedures as they would be unusable. Is there something I am missing?
UPDATED
I think I know why this happening but I don't know how to fix it. The SQL result set has dynamic columns as I use the pivot command in SQL. This means that if a user creates a new Gas company the result set will have another column and the datacontext must interpret that as the SP having changed and still shows the old dataset. This does mean I cannot just delete the SP from the datacontext and re-add it as the web application needs to handle if the user adds another company.
Any changes you make in SQL server are not auto-synched to your .dbml file. If you make table or stored procedure changes you need to delete them from the .dbml file and add them again.
Best practices would dictate that you don't pivot your data in SQL. Pivotting data is not a data related issue; it's presentation and should be done in the presentation layer -- in the application.
Related
I am modifying an access 2010 application so that it uses SQL server to run its queries. The data has been transferred to the server some times ago, and used as linked tables, but that proves a bit slow and non-optimal. So I'm trying to put the queries on the server.
I have no problem for simple queries, views,... and I'm using stored functions when there is a need for simple parameters (dates, ids,...).
But now I have a process in that application that selects a bunch of ids in the database, stores them in a local table, does a bunch of actions on them (report with sub report, print preview, print, update of the original records with the date of print when the user confirms that everything printed OK), and empties the local table if all actions succeed.
I can't simply use an SQL server table to store the ids since many people use the application at the same time, and the same table is used in several processes; I can't use temporary tables since they disappear as soon as access goes to the next action; and I can't find a way to use a local table as a parameter to server stored procedures. Basically I'm stuck.
Can anyone help? Is there a way to do that (pass a bunch of values as a table to a server stored function)? Or another process that would achieve the same result (have a table on the server specific to the current user, or a general table and somehow identify the lines belonging to current user, or anything else)?
There are 2 methods that I use. Both work very well for multi-user apps. Here are the basics. You'll need to work out the details.
Create a table (tblSessions) in SQL Server with an identity column SessID (INT NOT NULL).
Create a function in Access to generate and retrieve a new SessID.
Create a second SS table tblWork with 2 columns SessID, YourID. Add appropriate indexes and keys. Link this table to your Access app. Then instead of inserting the IDs for your query into an Access temp table, insert them into tblWork along with a new SessID. You can now join tblWork to other SS tables/views to use as the datasource for you reports. Be sure to add the SessID that you generated to your where clause.
Create a stored procedure to generate the data for your reports. Include a parameter #YourIDList VARCHAR(MAX). Call the proc via a passthrough queryand pass the list of your IDs as a comma (or whatever you prefer) separated string to #YourIDList. In the proc, split #YourIDList into a temp table. SS2016+ has a STRING_SPLIT function. For older versions, roll your own. There are plenty of examples available. Then join the temp table to the other tables you need to generate your output. Use the PT query as your report datasource, or dump it into an Access temp table and use that as you report datasource.
While comparing Database instance to a Database project in VS2010 using SSDT, it shows a difference in one of the Stored Procedures. The Store Procedure DDL script is exactly the same but when I expanded the Properties folder under the Store Procedure it show a difference in the DefaultExpressionScript.
The source SP shows this in the DefaultExpresionScript:
DefaultExpressionScript = at
While the destination SP has this:
DefaultExpressionScript = -1
I don't see where I can change this there is no such object called DefaultExpressionScript in my database project. where should I fix this?
This bug is still present in VS 2015 Update 3 with SSDT 14.0.61021.0. However, just scripting the stored procedure with ALTER ... in SSMS and running that query (which shouldn't change anything) fixed it for me. The schema comparison didn't show differences anymore afterwards.
The DefaultExpressionScript is the default value of one of the stored procedure's parameters. I suggest using Script As to get the TSQL definition of the stored procedure from the database and verifying that the stored procedure default values match what's in your database project.
Also, note that there have been a large number of bug fixes to schema comparison that aren't available in VS2010. Have you considered installing the latest version of Visual Studio 2015 Express with SSDT?
I finally found a workaround. You simply script the affected SP(s) for Modify and run the Alter statement, without changing anything. It corrects the values.
So far, I have created 3 tables in SQL using visual studio. They have been connected to my VB project file and I can view the data held within them using the Database Explorer.
My only problem is: how do I use/make available the data held within each table?
I need to write code which will add a Japanese character (from one of the tables that already exists) to a new table when a check box is ticked. Then I need to write code to update the table and save the changes.
I have absolutely no idea how to retrieve the data held in each table nor how to write a SQL query in VB.
Any help would be appreciated.
When trying to automate reading out constraint information using sp_helpconstraint I got the bright idea of pulling out the source code of the built-in SP directly and run it myself (since it returns multiple result sets so those can't be stored in a temp table). So I ran exec sp_helptext 'sp_helpconstraint' (on SQL Azure) to generate the source code, and copied it into a new query window.
However, when I run the SP (on SQL Azure), I get lot's of error messages -- for example, that object syscomments doesn't exist even though I am using the exact same source that runs perfectly when calling sp_helpconstraint directly. Just to make sure it wasn't an anomaly with the procedure or a mistake in my copy/paste execution, I tested the exact same procedure on SQL Server 2008, and if I directly copy the SP source into a new query window, it runs perfectly (obviously after removing the return statements and manually setting the input parameters).
What gives?? Do built-in SP's run in a special context where more commands are available than normal on SQL Azure version? Is sp_helptext not returning the actual source that is being run on SQL Azure?
If you want me to try anything out, give a suggestion and I can try it on our SQL Azure Development instance. Thanks!
I have to make a new report using crystal report8.5 .
I have created a stored procedure in SQL Server 2005. The stored procedure has one input parameter.
Now I wanna to know that how I can add that stored procedure and show its result in my report
while designing that report?
thank you
First go to File > Options > Database (going from memory) and make sure the checkbox for Stored Procedures is ticked. Then, when you setup your connection to SQL Server, as well as a Tables section you'll see a Stored Procedures one beneath it. Find your stored procedure in the list, add it as the data source for your report, and you'll be able to use it as a normal source.