Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat is wrong in my code to call a stored procedure
    primarykey
    data
    text
    <p>I Have created a Stored procedure dbo.test as follows</p> <pre><code> use sample go create procedure dbo.test as DECLARE @command as varchar(1000), @i int SET @i = 0 WHILE @i &lt; 5 BEGIN Print 'I VALUE ' +CONVERT(varchar(20),@i) SET @i = @i + 1 END </code></pre> <p>Now i am created a c# console application to call the stored procedure as follows</p> <pre><code> using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; namespace AutomationApp { class Program { public void RunStoredProc() { SqlConnection conn = null; SqlDataReader rdr = null; try { conn = new SqlConnection("Server=(TEST\\SQL2K5EXPRESS);DataBase=sample,IntegratedSecurity=SSPI"); conn.Open(); SqlCommand cmd = new SqlCommand("sample.dbo.test", conn); cmd.CommandType = CommandType.StoredProcedure; //cmd.ExecuteNonQuery(); rdr = cmd.ExecuteReader(); while (rdr.Read()) { Console.WriteLine(String.Format("{0}, {1}", rdr[0], rdr[1])); } } catch(Exception ex) { Console.writeLine(ex.message); } finally { if (conn != null) { conn.Close(); } if (rdr != null) { rdr.Close(); } } } static void Main(string[] args) { Console.WriteLine("Hello World"); Program p= new Program(); p.RunStoredProc(); Console.Read(); } } </code></pre> <p>}</p> <pre><code> O/P: Hello World //Could not find stored procedure 'test'. A network-related or instance-specific error occurred while establishing a conne </code></pre> <p>ction to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Serve r/Instance Specified)</p> <p>But when i try to run the program it was closing so i debugged the program then at exactly at executeReader() method it was showed that can not find the stored procedure "dbo.test" and when i give the "EXEC dbo.test" at SSMS it display the result as i expected.</p> <p>waht is wronng with this any Help greatly Appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload