我正在开发MVC应用程序,并且已经构建了一个函数来处理我的数据库连接,称为DBConn。在DBConn中,我有一个公共和共享的函数InsertSQL(qry,parr())。当我在本地计算机上进行测试时,一切正常,但是当我发布到Azure并查看实时站点时,我得到以下信息:
BC30456:“ InsertSQL”不是“ DBConn”的成员。
我具有的功能如下:
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Public Class DBConn
Public Shared Connstr As String
Public Shared Querystr As String
Public Shared Function InsertSQL(qryStr As String, ByRef parr() As Object) As Integer
Dim connection As SqlConnection = New SqlConnection()
Dim cmd As New SqlCommand
Dim qry As String = ""
connection.ConnectionString = ConfigurationManager.ConnectionStrings(Connstr).ConnectionString
connection.Open()
cmd.Connection = connection
Select Case qryStr
Case "addForumPost"
qry = "INSERT INTO ForumPosts(CreatedBy, CreatedDate, Sticky, Message, ForumID) VALUES ('" & parr(1) & "','" & parr(3) & "'," & "0" & ",'" & parr(0) & "'," & parr(2) & ")"
End Select
If qry <> "" Then cmd.CommandText = qry
cmd.ExecuteNonQuery()
connection.Close()
Return 0
End Function
End Class
为了简洁起见,我仅包含InsertSQL函数,但是还有其他功能完全相同的设置,但没有相同的问题。有任何想法吗?我认为它一定是Azure或访问/权限。
这是我在asp页面中调用函数的方式:
@<form method = "post" action="@HttpContext.Current.Request.Url.AbsolutePath">
<fieldset>
<p>Add Comment</p>
<p><textarea style="width:100%" rows="10" name = "comment" ></textarea></p>
<p><input type = "submit" name="addPost" value="Post" /></p>
@If IsPost = True Then
Dim rtnCode As Integer
Dim cn As New DBConn
Dim arr(0 To 3) As Object
If Request.Form("comment") <> "" Then
cn.Connstr = "kbl"
arr(0) = Request.Form("comment")
arr(1) = Session("userObject").username
arr(2) = HttpContext.Current.Request.RequestContext.RouteData.Values("id")
arr(3) = Now().ToString("yyyyMMdd hh:mm:ss")
rtnCode = cn.InsertSQL("addForumPost", arr)
End If
@<meta http-equiv='refresh' content='0'>
End If
</fieldset>
</form>