How to save a procedure against a database in SQL Server? - c#

So i'm following a tutorial on how to connect a database to WFA and at this step he saves the procedure, but don't know where because he skips.
My question: How do I save it inside the folder because whenever I want to save, it wants me to choose a path and doesn't save directly in the "Stored Procedures" folder.

To answer your question SQL SERVER automatically saves your stored procedures within the Programmability -> Stored Procedures -> Your SP upon creation.
Note : Always remember to refresh the Stored Procedures Folder after you have created a new Stored Procedure, otherwise you might not be able to see it (but its there, dont worry)
UPDATE
Here is a TSQL statement to create a Stored Procedure (of course you can change it to your own vision) :
USE YourDatabaseName
GO
CREATE PROCEDURE SchemaName.SPName
AS
SELECT * FROM SchemaName.TableName
GO
This will Create a Simple SP for your service (assuming you have excuted it). Now can look for it as above.
Remember You need to look for it within your SQL Server Management Studio. not within Visual Studio (Which you will be able to Call the SP later within your C# code using An ORM)

Suppose you are creating a procedure like below
CREATE PROC Test
AS
SELECT * FROM table_name
If you write this in SQL Server Management Studio and Execute (F5) against a DB, this will come under Programmability -> Stored Procedures.
Just execute the code and refresh the DB in Object Explorer and check under
Programmability -> Stored Procedures
OR
If you are trying to create the procedure from C# code, Just execute it like normal sql query through the C# code against the DB.
This will also create a procedure under Programmability -> Stored Procedures. Check SSMS in the same way as above to see.
OR
If you are trying to execute a stored procedure through C# code refer this

Related

Procedure or function has too many arguments specified, C# & SQL Server

I am developing my very first stored procedure in SQL Server 2012 and need advice concerning the error message I get.
C# code:
Stored procedure code:
In the example you showed, you are not using the stored procedure. The whole Program.sqlcmd.CommandType isn't being used, as you specify a different SQL string (st) to use.
You need to look at examples of how to do stored procedures from c#.
How to execute a stored procedure within C# program

How to input data into SQL Server for first time start of C# application

I created a C# program using SQL Server 2008 Express.
There is some data that must exist in the database table initially, for the C# application to run correctly.
I would like to transfer this data into the table the first time the C# application executes.
But I don't want this SQL data (record data) read from my C# code (I don't want to load this data from hard-coded C# code).
How does SQL Server store its record data, and how can I transfer the initial data into the database?
I'd try to not rely on a database being existent for your application to work. You're coupling yourself to the database which probably isn't a good idea. Do you think maybe you could execute a stored procedure from your application which would fill out the tables you're relying on? That way your DB creation code wouldn't exist in your application. This would however still mean your application is dependant on the database to function correctly.
I would recommend one of two plans, the latter being the cleaner.
Plan 1
Create a SQL script which will create and insert all the required data for the application to work and place this in a stored procedure
When your application starts first time it will check a configuration file to see if the program has ran before, if not, execute the stored procedure to create the required data
Alter an external configuration file (which could be password protected) which will indicate whether the stored procedure has already been run, could just be a simple bool
Each subsequent time the application runs it will check to see whether it's run before and won't execute the stored proc if it has
Plan 2
Create a SQL script which will create and insert all the required data for the application to work and place this in a stored procedure
Use an installer to deploy your application with a custom action to create the database, explained here
You definitely need to have the SQL insert/create script at least partially hardcoded somewhere. Either in an SQL script sitting in your app's directory (not recommended because the user might tamper with it) or in your application's ressources (a bit more secure as the user would need to hex-edit the EXE or DLL).
Tried this ? http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/43e8bc3a-1132-453b-b950-09427e970f31
I think your question is so simple and you want to fill the tables before you run the program.
simplely you can open sql server managment studio and and connect with your instance name,then expand Database list and find your database that you have created.expand that and in Tables tree find the table you want to add data to it.right click on it and do Edit
also Redgate has a product to fill tables called data generator,that can use to fill your tables with so many data

ADO.NET command to script database creation

Is there a SELECT command I can execute in ADO.NET to retrieve a script that will rebuild my database from scratch with empty tables? I'd like to be able to script the creation of the database itself, along with all the tables, views, and stored procedures and any relationships that exist between the tables. Also primary key and identity specifications.
I am using SQL Server 2000 and C# (.NET Framework 2.0).
There is no such SELECT command but you can use SQL Server Management Studio to generate such a script for you.
Context menu for a database in Object Explorer has Script Database as option that should do the trick for you. Then you could execute the resulting script from your program using standard SqlCommand objects.
Depending on what you are trying to do, you may consider to build your database structure into the model (System databases / model). Then, each time you'll create a new database, you'll get all the stuff you need already inserted into your new database.
But be warned that this solution will create all the stuff for ALL the new databases created.

stored procedure in SQL CLR

How do you write a stored procedure using C# in SQLCLR?
Currently I am using SQL Server Management Studio and I write stored procedures using T-SQL such as create proc sp_item as .....
See:
Building my first SQL CLR stored procedure
CLR Assembly RegEx Functions for SQL Server by Example
Choosing between CLR and T-SQL stored procedures: a simple benchmark
Basically, there are Visual Studio templates which allow you to get started with SQL CLR projects. Fill in the blanks, write your actual code, and you can even deploy those CLR assemblies into SQL Server directly from within Visual Studio.
One word of caution: I would refrain from doing set-based updates and inserts and stuff like that in a SQL CLR stored proc - for that, T-SQL stored procs are just plain better and faster.
SQL-CLR is great to extend SQL Server with stuff like string manipulation, date handling, ability to call e.g. web services or other stuff. I would recommend against trying to replace all T-SQL stored procs with C# SQL CLR stored procs just because you can or just because it's cool - use the right tool for the right job! Mass operations on sets are better left to T-SQL.
In addition to the links provided by Marc, I also wrote a short tutorial on writing SQLCLR Table-Valued Functions (FYI, free registration is required to view articles on SQL Server Central):
CLR Table-Valued Function Example with Full Streaming (STVF / TVF)
I have also been writing a series of articles about working with SQLCLR in general:
Stairway to SQLCLR
Also, you should not use sp_ as a prefix in stored procedure names. That is a special syntax that degrades performance due to causing SQL Server to first check for that stored procedure in master, and then, if not found there, it will search the current database.

Using MySql stored procedures for .NET Data Access Layer

I'm using .NET 2.0 and/or 3.5. Weird thing is, everytime I add a query, whether via TableAdapter or a plain query in a Dataset, using a MySQL stored procedure (whether be a select, update, insert, delete), the wizard doesn't finish (the dialog suddenly disappears, I'm back to designer mode and the query isn't added to the tableadapter or dataset form). Is there a special formatting required for MySQL stored procedures, or a workaround for MySQL stored procedures to work?
I'm using
MySQL 5.1.33
portable XAMPP 1.7.1
PHP 5.2.9
Apache 2.2.11
phpMyAdmin 3.1.3.1
I was having this same thing happen. The fix for me was the following: One of my parameters for the stored procedure was 'filter'. I changed it to 'p_filter' and the issue went away. The issue that I am still dealing with is on the last screen of the filter I get:
you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near 'NULL' at line 1
I brought in a stored procedure that doesn't accept a parameter and I have no issues with creating the TableAdapter using the dataset wizard.

Categories

Resources