ASP.NET:我在尝试运行sql脚本时遇到问题
我已经安装了Microsoft SQL Server 2014 Express,正在学习如何使用ASP.NET和Visual Studio Express 2015 for Web从名为ASP.NET:我在尝试运行sql脚本时遇到问题,sql,asp.net,sql-server-2014-express,Sql,Asp.net,Sql Server 2014 Express,我已经安装了Microsoft SQL Server 2014 Express,正在学习如何使用ASP.NET和Visual Studio Express 2015 for Web从名为vetDatabase_Wizard的兽医数据库检索数据 首先,我从输入的ID中检索一个protocolID,并将信息存储在一个名为clinicalCase的类中。我100%不熟悉SQL 下面是我的SQLQuery1.sql脚本(尝试): 下面是调用我的SQL脚本的getCaseByID函数: [WebMetho
vetDatabase_Wizard
的兽医数据库检索数据
首先,我从输入的ID中检索一个protocolID
,并将信息存储在一个名为clinicalCase
的类中。我100%不熟悉SQL
下面是我的SQLQuery1.sql
脚本(尝试):
下面是调用我的SQL脚本的getCaseByID
函数:
[WebMethod]
public clinicalCase getCaseByID(int ID)
{
// Retrieve connection string
string cs = ConfigurationManager.ConnectionStrings["vetDatabase_Wizard"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("spGetCaseByID", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter parameter = new SqlParameter("@ID", ID);
cmd.Parameters.Add(parameter);
clinicalCase cases = new clinicalCase();
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
cases.ID = Convert.ToInt32(reader["ID"]);
cases.protocolID = Convert.ToInt32(reader["protocolID"]);
}
return cases;
}
}
当我运行函数并尝试它时,我在
SqlDataReader reader = cmd.ExecuteReader();
找不到存储过程“spGetCaseByID”
我怀疑是我的SQL语法,或者是我在web.config文件中添加了一个连接字符串,因为我没有:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="vetDatabase_Wizard"
connectionString="Data Source=JOHNATHANBO431E\SQLEXPRESS2014;Initial Catalog=vetDatabase_Wizard;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
</system.webServer>
</configuration>
我从数据库的属性面板中获取了名称和连接字符串
我非常感谢社区的反馈,因为我肯定错过了一些明显的东西!我非常感谢您抽出时间!:)
编辑:我意识到我需要先在SQLServerManagementStudio中执行SQL脚本,然后再在VisualStudio中使用它
但是,我得到以下错误:
SQL80001:语法不正确:“CREATE PROCEDURE”必须是批处理中的唯一语句。维塔普
因此,我的SQL脚本是错误的,需要调试帮助。您的代码正在尝试运行一个名为
spGetCaseByID
的SQL Server存储过程。
数据库中不存在此存储过程。您的代码正在尝试运行名为
spGetCaseByID的SQL Server存储过程。
。
数据库中不存在此存储过程。您正试图在
SQL
中运行多个命令。为了创建存储过程,它应该是第一行代码,或者将go
放在多个sql命令之间
Select * from tblCases
开始
CREATE PROCEDURE spGetCaseByID
@ID int
**AS**
BEGIN
SELECT caseID, protocolID
FROM tblCases
WHERE caseID = @ID
END
这将有助于您尝试在
SQL
中运行多个命令。为了创建存储过程,它应该是第一行代码,或者将go
放在多个sql命令之间
Select * from tblCases
开始
CREATE PROCEDURE spGetCaseByID
@ID int
**AS**
BEGIN
SELECT caseID, protocolID
FROM tblCases
WHERE caseID = @ID
END
这将有助于你好,伊恩!感谢您的反馈!我刚刚发现:我必须先执行它才能被存储。保存文件不行。嗨,伊恩!感谢您的反馈!我刚刚发现:我必须先执行它才能被存储。保存文件不行。谢谢你的帮助!成功了!太简单了P所以“Go”将把它分解为两个命令,对吗?谢谢你的帮助!成功了!太简单了所以“Go”会把它分解成两个命令,对吗?