Tag: SQL服务器

SCOPE_IDENTITY()始终返回0

我的存储过程是: ALTER PROCEDURE [dbo].[Insert_QuickLabDump] @Specimen_ID [varchar](50), @Client_Key int, @Outcome [varchar](50), @Medications [varchar] (max), @Date_Collected date, @Time_Collected time(0) , @Date_Entered date, @Time_Entered time(0) , @Date_Completed date, @Time_Completed time(0) , @Test_Date date , @Test_Time time(0) , @Practice_Name [varchar] (500), @Practice_Code [varchar] (500), @Client_ID [varchar] (500), @Requesting_Physician [varchar] (500), @Other_Medications [varchar] (max), @Order_Comments [varchar] (max), @Reference_Number [varchar] (500), […]

检测SQL Server是否正在运行

我正在寻找一种方法来轮询不同的服务器并检查SQL服务器是否正常运行。 我正在用C#编写代码。 我并不特别关心单个数据库,只是SQL服务器正在运行并且响应迅速。 有任何想法吗?

Sql Server临时表消失

我正在创建一个临时表#ua_temp,它是常规表的子集。 我没有收到错误,但是当我在第二步尝试从#ua_temp中选择时,它没有找到。 如果删除#,则会创建名为ua_temp的表。 我使用了与其他地方的SELECT INTO创建表完全相同的技术。 它运行正常,所以我不认为它与数据库设置有任何关系。 有谁能看到这个问题? // Create temporary table q = new StringBuilder(200); q.Append(“select policy_no, name, amt_due, due_date, hic, grp, eff_dt, lis_prem, lis_grp, lis_co_pay_lvl, “); q.Append(“lep_prem, lapsed, dn_code, [filename], created_dt, created_by “); q.Append(“into #ua_temp from elig_ua_response “); q.Append(“where [filename] = @fn1 or [filename] = @fn2 “); sc = new SqlCommand(q.ToString(), db); sc.Parameters.Add(new SqlParameter(“@fn1”, […]

使用C#连接到SQL Server 2012数据库(Visual Studio 2012)

晚上好, 我正在尝试从C#连接到SQL Server 2012数据库。 使用SQL Server Management Studio时的连接设置如下: – Server Type: Database Engine Server Name: Paul-PC\SQLEXPRESS Authentication: Windows Authentication Username: Greyed out Password: Greyed out 我正在尝试连接的数据库的名称是“testDB”。 这是我的代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace DatabaseConnection { public partial class Form1 : […]

允许用户传递表名和列名,同时防止SQL注入

我有一个(Intranet)网页(ASP.NET C#),它允许用户在SQL-Server中的特定数据库上创建一个表,表名和列名是自由文本字段,实际结构由几个确定下拉菜单。 我知道传递create table语句是因为纯文本字符串与我的文本框中的文本连接在一起容易受到SQL注入的影响。 鉴于我传递的是不存在的db对象的实际名称而不是参数,除了在连接字符串之前检查每个文本框是否包含非法字符之外,还有什么方法可以防止注入的可能性?

如何生成动态标签并使用列名和值作为文本

有没有办法,如果可以从代码隐藏动态生成ASP.net页面。 例: ASP.net: 代码隐藏: using (SqlConnection conn = new SqlConnection(gloString)) { try { strQuery = @””; SqlDataAdapter da = new SqlDataAdapter(strQuery, conn); DataSet myDataSet = new DataSet(); da.Fill(myDataSet); //dynamically generate label with the SQL column name as the Text //dynamically generate label with the SQL column value as the text // // //{SQL COLUMN NAME} […]

将List 插入SQL Server表

我有一个实体Report其值我想插入数据库表。 必须插入以下Report属性: reportID – int RoleID – int Created_BY = SYSTEM(default) CURRENT_TIMESTAMP 现在的问题是第二个属性。 我有一个包含LIST属性的报告。 ROLES是一个定义明确的实体,它有一个ID和一个NAME 。 从这个列表中,我必须提取每个角色并将每个角色的ID插入表中。 所以我的查询目前看起来如下: INSERT INTO REPORT_MARJORIE_ROLE(REPORT_ID, ROLE_ID, CREATED_BY, CREATED) VALUES({0}, {1}, ‘SYSTEM’, CURRENT_TIMESTAMP) 我解析这些值的C#代码如下: try { StringBuilder _objSQL = new StringBuilder(); _objSQL.AppendFormat(Queries.Report.ReportQueries.ADD_NEW_ROLES, report.ID, “report.MarjorieRoles.Add(MarjorieRole”)); _objDBWriteConnection.ExecuteQuery(_objSQL.ToString()); _objDBWriteConnection.Commit(); _IsRolesAdded = true; } 所以请指导我如何从C#函数添加角色

如果超时,查询会发生什么?

假设我有一个发送到我的SQL-Server数据库的查询,它需要超过30秒,并且我的程序抛出SQL Query Timeoutexception。 查询是否仍然在我的数据库上进行,或者在抛出exception后立即终止?

SQL连接公共IP,命名实例和端口号

我在c#中创建连接字符串时遇到了困难,该连接字符串将使用公共IP,命名实例和端口号(1433除外)连接到远程SQL服务器。 谁知道怎么做?

无法在生产ASP.net网站上加载文件或程序集Microsoft.SqlServer.SqlClrProvider,它在哪里?

在我的ASP.net站点上,我有一个对Microsoft.SQLserver.SMO的引用。 我将此引用复制到我的生产服务器上,并且无法加载Microsoft.SqlServer.Management.Sdk.Sfc错误。 通过从中复制dll来修复此错误 C:\Program files\Microsoft Sql Server\110\SDK\Assembilies 但是,我得到了相同的错误,但对于无法找到的Microsoft.SqlServer.SqlClrProvider 。 我在哪里可以找到SqlClrProvider dll? 它适用于我的localhost所以它必须在某个地方。