SQL Store Procedure

Apllication runs store procedure but no data in database.

Page 1 of 1

1 Replies - 711 Views - Last Post: 22 May 2010 - 09:33 AM Rate Topic: -----

#1 LouisF22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-October 09

SQL Store Procedure

Posted 21 May 2010 - 11:03 AM

Hi

I'm trying to run this Store Procedure in my application. The code runs without problems but my database stays empty.

C# code:
SQLConnection.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + @"|DataDirectory|\Server Info.mdf" + ";Integrated Security=True;Connect Timeout=30;User Instance=True";
SQLConnection.Open();
                    
                    SqlCommand SQLCommand = new SqlCommand("insertHddInfo",SQLConnection);

                    SQLCommand.CommandType = CommandType.StoredProcedure;

                    
                    SQLCommand.Parameters.Add("@dateInsert", SqlDbType.Date);
                    SQLCommand.Parameters["@dateInsert"].Value = DateTime.Now.ToShortDateString();
                    SQLCommand.Parameters.AddWithValue("@serverIP", txtComputerIP.Text);
                    SQLCommand.Parameters.AddWithValue("@serverName", txtComputerIP.Text);
                    SQLCommand.Parameters.AddWithValue("@hardDriveName",oReturn["Name"].ToString());
                    SQLCommand.Parameters.AddWithValue("@totalSpace", dblTotalSpace); 
                    SQLCommand.Parameters.AddWithValue("@usedSpace", dblUsedSpace);
                    SQLCommand.Parameters.AddWithValue("@usedPercentage", dblUsedPercentage);
                    SQLCommand.Parameters.AddWithValue("@freeSpace", dblFreeSpace);
                    SQLCommand.Parameters.AddWithValue("@freeSpacePersentage", dblFreePercentage);

                    SQLCommand.ExecuteNonQuery();
                    SQLConnection.Close();



SQL Procedure
USE [Server Info]
GO
/****** Object:  StoredProcedure [dbo].[insertHddInfo]    Script Date: 05/21/2010 19:57:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[insertHddInfo]
	-- Add the parameters for the stored procedure here
	 @dateInsert date,
	 @serverIP text,
	 @serverName text,
	 @hardDriveName text,
	 @totalSpace decimal,
	 @usedSpace decimal,
	 @usedPercentage float,
	 @freeSpace decimal,
	 @freeSpacePersentage float	 
AS
BEGIN
    -- Insert statements for procedure here
	INSERT INTO dbo.hddInfo (dateInsert,serverIP,ServerName, hardDriveName, totalSpace, usedSpace, usedPercentage, freeSpace, freeSpacePersentage)
    VALUES (@dateInsert,@serverIP,@ServerName,@hardDriveName,@totalSpace,@usedSpace,@usedPercentage,@freeSpace,@freeSpacePersentage)
END



Is This A Good Question/Topic? 0
  • +

Replies To: SQL Store Procedure

#2 Charles:)  Icon User is offline

  • D.I.C Regular

Reputation: 130
  • View blog
  • Posts: 316
  • Joined: 26-November 09

Re: SQL Store Procedure

Posted 22 May 2010 - 09:33 AM

The first thing to do is check that the stored procedure definitely works. Try running it from within SQL Server Management Studio rather than executing it programmatically. If it works there then you can check your code for errors.

This post has been edited by Charles:): 22 May 2010 - 09:33 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1