I do not have admin panel on my website (I find it overkill) and use default local MS Studio Server Explorer to admin my website's database. I use Views and it works great for my purposes. But now I need parametrized View and I created Stored Procedure. But I didn't find a way how to display result set of SP as View does it. It sends data to Output window instead of Server Explorer's grid view. Any ideas?
you can run the stored proc using "EXEC", this will put the results in a grid at the bottom of the screen. i.e.
exec mySp 'Param'
Related
We currently update manually each remote database table with changes made on local one. I mean adding tables, tables columns, etc. not the data they contain. The remote database is live in production so it's always newer.
The database type is SQL Server a we normally use SSMS to change it on both remote and local machine. The website is ASP.NET MVC4 with EntityFramework 4.2
Thanks.
In SSMS in your local database, after you make changes to the table in design view, if you right click on an empty white row at the bottom you can select 'Generate change script'. This will generate a script which you can then run on the remote server to automatically apply your changes that were made to the local database.
If you want to update the tables automatically (not sure if thats what you ask), you should check out Migrations for EF: https://msdn.microsoft.com/en-us/data/jj591621.aspx
I am having a strange problem. One of my stored procedure is getting dropped automatically.
Its not that I am creating it in a wrong place. Every time I create the SP and execute my web page, it shows. After few min, if I execute the page again, it displays a error message which is due to missing SP.
I have tried recreating again and again, and everytime it repeats. I even did restart the machine (Windows Server 2008 R2), but no use. The same procedure is fine on my SQL Server instance on Windows 8 machine.
I tried the SQL Server Profiler, but of no use. Don't see any drop procedure.
Also for some strange reason, I am getting a lot of requests every second to my SQL Server which is hosting a dotnetnuke based website. Can someone help me with this.
Thanks
Just had this issue presented by another developer. It turned out that there was a "DROP procedure" included at the end of another SP.
To look for such hidden statement in another database SP, run a statement like
select OBJECT_NAME(sc.id), sc.* from syscomments sc where text like '%<name_of_SP>%'
where <name_of_SP> is the SP being dropped.
I had this same problem, and the issue was a missing GO in the DB script between a stored procedure create script and a drop of another stored procedure.
The solution was to add a GO between stored procedure 1 create and stored procedure 2 drop.
I referred to Stored Procedure gets dropped randomly.
Usually connect to an external database but I wanted to fiddle with creating a project with a local database. I am using SQLServer Express Local Database, not CE.
I can add tables with EF but if I right click on Tables in Server Explorer the only options I have are Refresh and Properties, i.e. no Add Table menu option. Similarly, if I right click on one of the tables EF has created I also get only the Refresh and Properties menu options so I can't add rows, etc. Same problem with stored procedures; I can't add any (should I want to do some testing with EF and stored procedures) because I only have the Refresh and Properties menu options.
FOLLOW UP:
I have isolated this problem to VS2012 Professional. When I use VS2010 it works exactly as expected: I can add tables and stored procedures. Following the same steps with VS2012 results in the situation where there is no menu option to add either tables or stored procedures. I produced these test results with SQLServer 2012 LocalDB.
If you only see Refresh and Properties when you right click on Tables in Server Explorer, you probably need to install SQL Server Data Tools from http://msdn.microsoft.com/en-us/data/hh297027 .
I had a similar problem only with Visual Studio 2012 Express for Web following along with the "Getting started with ASP.Net MVC3" at www.asp.net. The tutorial used a Sql Server Compact edition but I have SQL Express 2012 so I changed the connection string to have the data source point at my local instance, .\SQLExpress2012. The app worked fine and was able to read and write to the database. However I could not edit the database in the Visual Studio Express Database Explorer (all the context menu options were missing except "refresh" and "properties).
I found that changing the data source in the connection string to "Data Source=(LocalDB)\v11.0;" fixed the problem. I read somewhere that if you use LocalDb instead of the SQL Server instance name then it will be accessed under your user account - must have been some kind of permissions issue.
The whole (working) connnection string is:
"Data Source=(LocalDB)\v11.0;AttachDBFilename=|DataDirectory|Movies.mdf;Integrated Security=True;"
Hope this saves someone a bunch of hours pulling their hair out, I'm almost bald now :)
I found that when installing Visual Studio 2013, I had not requested the 'SQL Server Data Tools' feature.
By re-running the installer from 'Control Panel' > 'Programs and Features', using the 'Modify' option, I could add the missing feature. On completion, the 'Add New Table' menu item was available.
The only way I can determine in VS 2012 to open an existing stored procedure for modification and save changes is the following:
1) Manually remove the initial word CREATE and retype ALTER in its place (every time).
2) From the "SQL" menu, then its "Transact-SQL Editor" submenu, choose Execute.
Given that VS2012 is in Release Candidate, I'm certain there will be no fundamental changes along these lines.
And, I understand that from a purist point of view that this is executing a query to change the procedure on the server. But from a usability point of view is there no longer a near-equivalent to a simple Save button on a toolbar? Over the course of day this is a not-inconsequential waste of time and mental focus. I could live with Ctrl+Shift+E but manually editing CREATE to ALTER every time is ridiculous.
I take it that you're trying to apply changes to a stored procedure to your database?
You can try the following:
Go to View SQL Server Object Explorer. Right click on the SQL Server node and add your server. Open the database and identify the procedure you need to edit. Double click on the procedure, which opens the CREATE script for the object. Leave the CREATE there and simply modify this and click the 'Update' button. Then select Generate Script or Update database depending on whether you want to apply the changes immediately or generate the script to a query window and apply the script yourself.
If you want to generate an ALTER, you can use the Server Explorer (as distinct from the SQL Server Object Explorer, which is also in the View menu). Add your database to Data Connections. Find your procedure, right click and select Open.
I'm fairly certain you can add the procedure to source control, make changes, check in, and publish to your DB. I've never done it, but its talked about in this video:
SSDT talk at TechEd 2012
I am using Crystal Reports in my application. Now, I have created an SQL view in my SQL Server database. Can I use this view as data source for Crystal Reports?
I know that we can use a stored procedure as data source for Crystal Reports, but I don't know that we can use a view as data source for the same.
Can any one give me some more ideas regarding the same?
In SQL Server Manager:
Ensure that the grants are set correctly (perhaps SELECT to PUBLIC)
In Crystal Reports:
Select Database | Database Expert...
Expand the desired database node
Expand the 'View' node
Select desired view
You may link views to other views and also to tables.