所有新的存储过程都会导致executiontenonquery:commandtext属性尚未初始化 [英] ALL new stored procedures result in executenonquery: commandtext property has not been initialized

查看:61
本文介绍了所有新的存储过程都会导致executiontenonquery:commandtext属性尚未初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL 2008服务器上创建了许多工作存储过程,但现在它们都导致了同样的错误:ExecuteNonQuery:CommandText属性尚未初始化。我采用了我验证的现有程序,以不同的名称创建,验证了相同的用户具有相同的权限,并且每次都得到错误。我创建了一个新的/独立的数据库。我重新启动了SQL服务,没有任何区别。我要重新启动服务器...



非常感谢任何帮助!



< br $>








您会注意到唯一的区别是名称程序



spIvrCntyDD = 703

spRptByHoursSums = CommandText属性尚未初始化



工作:



-VB代码:

objConn1 =新的SqlConnection(WebConfigurationManager.ConnectionStrings(SqlConn1)。ConnectionString)< br $> b $ b objConn1.Open()



objComm1 =新的SqlCommand(ConfigurationManager.AppSettings(spIvrCntyDD),objConn1)

objComm1.CommandType = CommandType.StoredProcedure

objComm1.Parameters.AddWithValue(@ strMyId,6904​​)

objComm1.ExecuteNonQuery()

objDR1 = objComm1.ExecuteReader()

如果objDR1.Read()= False那么

''''''''''''''''' '
HttpContext.Current.Response.Write(     / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /

读=假



''''''''''''''''''''''' '$'
>否则

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '$'
HttpContext。'$'$' Current.Response.Write(

Read = True - &修剪(objDR1.GetValue(0))&



''''''''''''''''''''' '$'$'
结束如果

objDR1.Close()

objComm1.Dispose ()



objConn1.Close()

objConn1.Dispose()





-Procedure:

USE [PacsesIVR]

GO

/ ******对象:StoredProcedure [dbo]。[spIvrCntyDD]脚本日期:10/4/2018 11:29:33 AM ****** /

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO



更改程序[dbo]。[spIvrCntyDD](



@strMyId VARCHAR(50)





AS

BEGIN

声明@strType VARCHAR(MAX)

声明@strCounty VARCHAR(MAX)

声明@ strDate1 VARCHAR(MAX)

声明@ strDate2 VARCHAR(MAX)



SET @strType ='Hours1'

SET @strCounty ='亚当斯'

SET @ strDate1 ='9/19/2018'

SET @ strDate2 ='9/30/2018'



/ *按小时来电 - 总计* /

如果@strType ='hours1'

选择Sum(dbCount)作为dbCount

来自tblIvrRptCallsByHour

其中dbCounty =''+ @strCounty +''

和dbDate在''+ @ strDate1 +''和''+ @ strDate2 +''



END









不工作:



-VB代码:

objConn1 =新的SqlConnection(WebConfigurationManager.ConnectionStrings(SqlConn1)。ConnectionString)

objConn1.Open()



objComm1 =新的SqlCommand(ConfigurationManager.AppSettings(spRptByHoursSums),objConn1)

objComm1.CommandType = CommandType.StoredProcedure

objComm1.Parameters.AddWithValue(@ strMyId,6904​​)

objComm1.ExecuteNonQuery()

objDR1 = objComm1.ExecuteReader()

如果objDR1.Read()= False那么

'''''''''''''''''''' '$'$'
HttpContext.Current.Response.Write(

Read = false



'''''''''''''''''''''''' ''''''''

Else

'''''''''''''''''''''' '$'$'
HttpContext.Current.Response.Write(

Read = True - &修剪(objDR1.GetValue(0))&



''''''''''''''''''''' '$'$'
结束如果

objDR1.Close()

objComm1.Dispose ()



objConn1.Close()

objConn1.Dispose()





-Procedure:

USE [PacsesIVR]

GO

/ ******对象:StoredProcedure [dbo]。[spRptByHoursSums]脚本日期:10/4/2018 11:26:56 AM ****** /

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO



ALTER PROCEDURE [dbo]。[spRptByHoursSums](



@strMyId VARCHAR(50)





AS

BEGIN

声明@strType VARCHAR(MAX)

声明@strCounty VARCHAR(MAX)

声明@ strDate1 VARCHAR(MAX)

声明@ strDate2 VARCHAR(MAX)



SET @strType ='Hours1'

SET @strCounty ='Adams'

SET @ strDate1 = '9/19/2018'

SET @ strDate2 ='9/30/2018'



/ *按小时拨打电话 - 总计* /

如果@strType ='hours1'

选择Sum(dbCount)作为dbCount

来自tblIvrRptCallsByHour

其中dbCounty =''+ @strCounty +''

和dbDate之间''+ @ strDate1 +''和''+ @ strDate2 +''



结束



我尝试过:



- 从头开始创建新的存储过程

通过复制工作过程中的代码来处理新的存储过程

-Restarted SQL服务



- 处理过的新数据库:现有的进程转移到数据库工作,但是新的数据库没有

解决方案

它与之无关存储过程在数据库上。它与调用它的VB.NET代码有关,但由于你从未显示过这些代码,我们无法告诉你你做错了什么。



我可以告诉你的是,执行存储过程的代码没有正确指定存储过程名称(如果有的话)。


你从中获取存储过程的名称您的应用设置文件,无论是app.config还是web.config。



您显然没有名为spRptByHoursSums的文件中的设置条目。如果设置不存在,ConfigurationManager将返回null。在指定命令文本时,在该参数中放置null与将String.Empty放在那里没有什么不同。


您会注意到唯一的区别是过程的名称



工作:

 -VB代码:
objConn1 =新的SqlConnection(WebConfigurationManager.ConnectionStrings(SqlConn1)。ConnectionString)
objConn1 .Open()

objComm1 =新的SqlCommand(ConfigurationManager.AppSettings(spIvrCntyDD),objConn1)
objComm1.CommandType = CommandType.StoredProcedure
objComm1.Parameters.AddWithValue( @strMyId,6904​​)
objComm1.ExecuteNonQuery()
objDR1 = objComm1.ExecuteReader()
如果objDR1.Read()= False那么
'''''''' '
HttpContext。''''''''''' Current.Response.Write(< div> Read = false< / div>)
'''''''''' '
其他
''''''''' '
HttpContext.Current.Response.Write(< div> Read = True - &修剪(objDR1.GetValue(0))& < / div>)
''''''''''''''''''''''' ''''''''''''
结束如果
objDR1.Close()
objComm1.Dispose()

objConn1.Close()
objConn1.Dispose()


-Procedure:
USE [PacsesIVR]
GO
/ ******对象: StoredProcedure [dbo]。[spIvrCntyDD]脚本日期:10/4/2018 11:29:33 AM ****** /
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo]。[spIvrCntyDD](

@strMyId VARCHAR(50)


AS
BEGIN
声明@strType VARCHAR(MAX)
声明@strCounty VARCHAR(MAX)
声明@ strDate1 VARCHAR(MAX)
声明@ strDate2 VARCHAR(MAX)

SET @strType ='Hours1'
SET @strCounty ='Adams'
SET @ strDate1 ='9/19/2018'
SET @ strDate2 = '9 / 30/2018'

/ *按小时调用 - 总计* /
如果@strType ='hours1'
选择Sum(dbCount)作为dbCount
来自tblIvrRptCallsByHour
其中dbCounty =''+ @strCounty + ''
和dbDate之间''+ @ strDate1 +''和''+ @ strDate2 +''

结束







不工作:

 -VB代码:
objConn1 =新的SqlConnection(WebConfigurationManager.ConnectionStrings(SqlConn1)。ConnectionString)
objConn1.Open()

objComm1 =新的SqlCommand(ConfigurationManager.AppSettings(spRptByHoursSums),objConn1)
objComm1.CommandType = CommandType.StoredProcedure
objComm1.Parameters .AddWithValue(@ strMyId,6904​​)
objComm1.ExecuteNonQuery()
objDR1 = objComm1.ExecuteReader()
如果objDR1.Read()= False那么
''' ''
HttpContext.Current.Response.Write(< div> Read = false< / div>)
''''''''''''''' '
否则
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '
HttpContext.Current''''''''''' .Response.Write(< div> Read = True - &修剪(objDR1.GetValue(0))& < / div>)
''''''''''''''''''''''' ''''''''''''
结束如果
objDR1.Close()
objComm1.Dispose()

objConn1.Close()
objConn1.Dispose()


-Procedure:
USE [PacsesIVR]
GO
/ ******对象: StoredProcedure [dbo]。[spRptByHoursSums]脚本日期:10/4/2018 11:26:56 AM ****** /
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo]。[spRptByHoursSums](

@strMyId VARCHAR(50)


AS
BEGIN
声明@strType VARCHAR(MAX)
声明@strCounty VARCHAR(MAX)
声明@ strDate1 VARCHAR(MAX)
声明@ strDate2 VARCHAR(MAX)

SET @strType ='Hours1'
SET @strCounty ='Adams'
SET @ strDate1 ='9/19/2018'
SET @ strDate2 = '9 / 30/2018'

/ *按小时调用 - 总计* /
如果@strType ='hours1'
选择Sum(dbCount)为dbCount
来自tblIvrRptCallsByHour
其中dbCounty = ''+ @strCounty +''
和dbDate在''+ @ strDate1 +''和''+ @ strDate2 +''

END


I have created a number of working stored procedures on my SQL 2008 server, but now they all result in the same error: ExecuteNonQuery: CommandText property has not been initialized. I took an existing procedure that I verified still works, created it under a different name, verified the same user(s) have the same permissions, and get the error every time. I've created a new/separate database. I've restarted the SQL service which made no difference. I'm down to rebooting the server...

Any help is greatly appreciated!






You'll notice the only difference is the name of the procedure

spIvrCntyDD = 703
spRptByHoursSums = CommandText property has not been initialized

working:

-VB code:
objConn1 = New SqlConnection(WebConfigurationManager.ConnectionStrings("SqlConn1").ConnectionString)
objConn1.Open()

objComm1 = New SqlCommand(ConfigurationManager.AppSettings("spIvrCntyDD"), objConn1)
objComm1.CommandType = CommandType.StoredProcedure
objComm1.Parameters.AddWithValue("@strMyId", 6904)
objComm1.ExecuteNonQuery()
objDR1 = objComm1.ExecuteReader()
If objDR1.Read() = False Then
'''''''''''''''''''''''''''''''''''''''''''''''''''
HttpContext.Current.Response.Write("

Read = false

")
'''''''''''''''''''''''''''''''''''''''''''''''''''
Else
'''''''''''''''''''''''''''''''''''''''''''''''''''
HttpContext.Current.Response.Write("

Read = True - " & Trim(objDR1.GetValue(0)) & "

")
'''''''''''''''''''''''''''''''''''''''''''''''''''
End If
objDR1.Close()
objComm1.Dispose()

objConn1.Close()
objConn1.Dispose()


-Procedure:
USE [PacsesIVR]
GO
/****** Object: StoredProcedure [dbo].[spIvrCntyDD] Script Date: 10/4/2018 11:29:33 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[spIvrCntyDD](

@strMyId VARCHAR(50)

)
AS
BEGIN
Declare @strType VARCHAR(MAX)
Declare @strCounty VARCHAR(MAX)
Declare @strDate1 VARCHAR(MAX)
Declare @strDate2 VARCHAR(MAX)

SET @strType = 'Hours1'
SET @strCounty = 'Adams'
SET @strDate1 = '9/19/2018'
SET @strDate2 = '9/30/2018'

/* Calls by Hour - Totals */
If @strType = 'hours1'
Select Sum(dbCount) as dbCount
From tblIvrRptCallsByHour
Where dbCounty = '' + @strCounty + ''
And dbDate Between '' + @strDate1 + '' And '' + @strDate2 + ''

END




NOT working:

-VB code:
objConn1 = New SqlConnection(WebConfigurationManager.ConnectionStrings("SqlConn1").ConnectionString)
objConn1.Open()

objComm1 = New SqlCommand(ConfigurationManager.AppSettings("spRptByHoursSums"), objConn1)
objComm1.CommandType = CommandType.StoredProcedure
objComm1.Parameters.AddWithValue("@strMyId", 6904)
objComm1.ExecuteNonQuery()
objDR1 = objComm1.ExecuteReader()
If objDR1.Read() = False Then
'''''''''''''''''''''''''''''''''''''''''''''''''''
HttpContext.Current.Response.Write("

Read = false

")
'''''''''''''''''''''''''''''''''''''''''''''''''''
Else
'''''''''''''''''''''''''''''''''''''''''''''''''''
HttpContext.Current.Response.Write("

Read = True - " & Trim(objDR1.GetValue(0)) & "

")
'''''''''''''''''''''''''''''''''''''''''''''''''''
End If
objDR1.Close()
objComm1.Dispose()

objConn1.Close()
objConn1.Dispose()


-Procedure:
USE [PacsesIVR]
GO
/****** Object: StoredProcedure [dbo].[spRptByHoursSums] Script Date: 10/4/2018 11:26:56 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[spRptByHoursSums](

@strMyId VARCHAR(50)

)
AS
BEGIN
Declare @strType VARCHAR(MAX)
Declare @strCounty VARCHAR(MAX)
Declare @strDate1 VARCHAR(MAX)
Declare @strDate2 VARCHAR(MAX)

SET @strType = 'Hours1'
SET @strCounty = 'Adams'
SET @strDate1 = '9/19/2018'
SET @strDate2 = '9/30/2018'

/* Calls by Hour - Totals */
If @strType = 'hours1'
Select Sum(dbCount) as dbCount
From tblIvrRptCallsByHour
Where dbCounty = '' + @strCounty + ''
And dbDate Between '' + @strDate1 + '' And '' + @strDate2 + ''

END

What I have tried:

-Created new stored procedures from scratch
-Created new stored procedures by copying code from working procedures
-Restarted SQL service

-Created new database: existing proceedures moved to database work, but new ones do not

解决方案

It has nothing to do with the stored procedure on the database. It has everything to do with your VB.NET code that calls it, but since you never showed that code, we can't tell you what you did wrong.

All I can tell you is that the code to execute the stored procedure doesn't properly specify the stored procedure name, if at all.


You're getting the name of the stored procedure from your app settings file, be it app.config or web.config.

You apparently don't have an entry for a setting in the file called "spRptByHoursSums". The ConfigurationManager will return null if the setting doesn't exist. When specifying the command text, putting a null in that parameter is no different than putting String.Empty in there.


You'll notice the only difference is the name of the procedure

working:

-VB code:
  objConn1 = New SqlConnection(WebConfigurationManager.ConnectionStrings("SqlConn1").ConnectionString)
  objConn1.Open()

  objComm1 = New SqlCommand(ConfigurationManager.AppSettings("spIvrCntyDD"), objConn1)
  objComm1.CommandType = CommandType.StoredProcedure
  objComm1.Parameters.AddWithValue("@strMyId", 6904)
  objComm1.ExecuteNonQuery()
  objDR1 = objComm1.ExecuteReader()
  If objDR1.Read() = False Then
  '''''''''''''''''''''''''''''''''''''''''''''''''''
      HttpContext.Current.Response.Write("<div>Read = false</div>")
  '''''''''''''''''''''''''''''''''''''''''''''''''''
  Else
  '''''''''''''''''''''''''''''''''''''''''''''''''''
      HttpContext.Current.Response.Write("<div>Read = True - " & Trim(objDR1.GetValue(0)) & "</div>")
  '''''''''''''''''''''''''''''''''''''''''''''''''''
  End If
  objDR1.Close()
  objComm1.Dispose()

  objConn1.Close()
  objConn1.Dispose()


-Procedure:
  USE [PacsesIVR]
  GO
  /****** Object:  StoredProcedure [dbo].[spIvrCntyDD]    Script Date: 10/4/2018 11:29:33 AM ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO

  ALTER  PROCEDURE [dbo].[spIvrCntyDD](

  @strMyId VARCHAR(50)

  )
  AS
  BEGIN
    Declare @strType VARCHAR(MAX)
    Declare @strCounty VARCHAR(MAX)
    Declare @strDate1 VARCHAR(MAX)
    Declare @strDate2 VARCHAR(MAX)
  
    SET @strType = 'Hours1'
    SET @strCounty = 'Adams'
    SET @strDate1 = '9/19/2018'
    SET @strDate2 = '9/30/2018'

    /*  Calls by Hour - Totals  */
    If @strType = 'hours1'
      Select Sum(dbCount) as dbCount
      From tblIvrRptCallsByHour
      Where dbCounty = '' + @strCounty + ''
        And dbDate Between '' + @strDate1 + '' And '' + @strDate2 + ''

  END




NOT working:

-VB code:
  objConn1 = New SqlConnection(WebConfigurationManager.ConnectionStrings("SqlConn1").ConnectionString)
  objConn1.Open()

  objComm1 = New SqlCommand(ConfigurationManager.AppSettings("spRptByHoursSums"), objConn1)
  objComm1.CommandType = CommandType.StoredProcedure
  objComm1.Parameters.AddWithValue("@strMyId", 6904)
  objComm1.ExecuteNonQuery()
  objDR1 = objComm1.ExecuteReader()
  If objDR1.Read() = False Then
  '''''''''''''''''''''''''''''''''''''''''''''''''''
      HttpContext.Current.Response.Write("<div>Read = false</div>")
  '''''''''''''''''''''''''''''''''''''''''''''''''''
  Else
  '''''''''''''''''''''''''''''''''''''''''''''''''''
      HttpContext.Current.Response.Write("<div>Read = True - " & Trim(objDR1.GetValue(0)) & "</div>")
  '''''''''''''''''''''''''''''''''''''''''''''''''''
  End If
  objDR1.Close()
  objComm1.Dispose()

  objConn1.Close()
  objConn1.Dispose()


-Procedure:
  USE [PacsesIVR]
  GO
  /****** Object:  StoredProcedure [dbo].[spRptByHoursSums]    Script Date: 10/4/2018 11:26:56 AM ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO

  ALTER  PROCEDURE [dbo].[spRptByHoursSums](

  @strMyId VARCHAR(50)

  )
  AS
  BEGIN
    Declare @strType VARCHAR(MAX)
    Declare @strCounty VARCHAR(MAX)
    Declare @strDate1 VARCHAR(MAX)
    Declare @strDate2 VARCHAR(MAX)
  
    SET @strType = 'Hours1'
    SET @strCounty = 'Adams'
    SET @strDate1 = '9/19/2018'
    SET @strDate2 = '9/30/2018'

    /*  Calls by Hour - Totals  */
    If @strType = 'hours1'
      Select Sum(dbCount) as dbCount
      From tblIvrRptCallsByHour
      Where dbCounty = '' + @strCounty + ''
        And dbDate Between '' + @strDate1 + '' And '' + @strDate2 + ''

  END


这篇关于所有新的存储过程都会导致executiontenonquery:commandtext属性尚未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆