sqlcommand

SqlCommand object, what length of time for CommandTimeout?

自作多情 提交于 2019-11-30 01:07:22
问题 How do I decide what length of time to use as a timeout when using an SqlCommand object? On parts of the code I'm working on (written by somebody else) I have: cmd.CommandTimeout = 60; Which I think is quite short. However, I have seen some people in forums talking about setting it to 30000, which seems too long. How do I know what is best for my application? 回答1: It seems that people are confused as to whether this is seconds or milliseconds. The documentation states that the timeout is in

SqlCommand read one value

混江龙づ霸主 提交于 2019-11-29 15:37:46
I have a problem with the value returned from SqlCommand , I have this code: string sqlSelect = "Select TOP 1 Quotation.SentToSupp as SentToSupp FROM Quotation JOIN Notifications ON Quotation.QuotationId = QuotationID "; SqlCommand Comm = new SqlCommand(sqlSelect, this.Connection); sqlSelect query selects the first DateTime value. When I call to SqlCommand I want to get this value (just one value). I add the query and my connection fine. But I don't know how to get my DateTime value... Must to use something like ExecuteReader ? Thank you in advance!! Use SqlCommand.ExecuteScalar method -

How do I run large SQL scripts that contain many keywords, including “GO” using C#?

て烟熏妆下的殇ゞ 提交于 2019-11-29 15:33:06
I'm creating a web application that serves as a front end to do SQL Replication. I have many scripts stored in the properties of the program. Let's use the first one as an example. The first script is the script that you get from creating a publication on the publisher server. USE [<<SOURCE_DATABASE_NAME>>] EXEC sp_replicationdboption @dbname = N'<<SOURCE_DATABASE_NAME>>', @optname = N'publish', @value = N'true' GO USE [<<SOURCE_DATABASE_NAME>>] EXEC [<<SOURCE_DATABASE_NAME>>].sys.sp_addlogreader_agent @job_login = N'XXX\Admin', @job_password = NULL, @publisher_security_mode = 0, @publisher

c# execute SqlCommand with Parameters in “using” code block

邮差的信 提交于 2019-11-29 15:09:28
I am attempting to execute an SQL Command through a 'using' code block, but can't seem to get it to work with Parameters. I get the error: 'Parameters does not exist in the current context', does anyone have a possible solution for this problem? Heres My code: DataTable dt = new DataTable(); using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) using (var cmd = new SqlCommand(" SELECT FName" + " FROM EmployeeTable " + " WHERE EmployeeId = @empId", con) { Parameters.Add(new SqlParameter("@empId",empId)) }) { try { con.open(); dt.Load

Create SQL Server table programmatically

随声附和 提交于 2019-11-29 14:38:59
I need to programmatically create a SQL Server 2008 table in C# such that the columns of the table should be generated from a list of columns (each column name is the name of a row in the table) My question is what is the command string to loop through the list of columns and creates the table's recorded: List<string> columnsName = ["col1","col2","col3"] I want to create a table with the columns in the columnsName . But since the list size in not constant, I need to loop through the list to generate the table columns. The simple answer is CREATE TABLE table_name ( column_name1 data_type,

C# Update Table using SqlCommand.Parameters ASP.NET [duplicate]

╄→гoц情女王★ 提交于 2019-11-29 13:02:49
Possible Duplicate: C# Update Table using SqlCommand.Parameters I'm trying to update an SQL Server table using SqlCommand, I think it's a syntax error with my T-SQL, but here is what I have so far: SqlCommand sqlCmd = new SqlCommand( "UPDATE yak_tickets SET email = @emailParam, subject = @subjectParam, text = @textParam, statusid = @statusIDParam, ticketClass = @ticketClassParam WHERE id = @ticketIDParam", sqlConn); The parameters are working as they should, however, the table never gets updated when I run the code. Any help would be appreciated =) Here is the rest of the code: #region

How to clear mysql screen console in windows?

我与影子孤独终老i 提交于 2019-11-29 10:36:00
问题 The title is my question. I googled and try something like mysql> !\ clear mysql> !\ cls mysql> system cls mysql> system clear blah blah ... but none of them works. anyone show me how to clear screen, just like cls command in window 回答1: This is not possible on Windows. There is an open bug for this issue: Bug #58680: Windows Clear Screen Command 回答2: EDIT: I don't think Any of the commands will work. In linux Ctrl-L will do the job. in windows there is no equivalent. You can only Exit MySql,

Save byte array in sql server

萝らか妹 提交于 2019-11-29 09:10:48
Am looking to use an approach in saving passwords that requires using byte array as in this post So which data type should i use in sql server to save byte array? and how can i pass and retrieve the byte array using SqlCommand? If it's always going to be the same length, then binary(length) would be suitable. If it's going to vary in length, use varbinary(maxlength) . binary and varbinary . And, as @p.s.w.g says, you pass it from code by placing it into a suitable parameter. Just use a byte[] the same way you would any other parameter, specifying SqlDbType.Binary as the parameter type. Here a

Is SqlConnection / SqlCommand thread safe?

丶灬走出姿态 提交于 2019-11-29 07:34:27
I am currently creating a WCF web service. As part of its job, it will unfortunately need to do some fairly intensive computations, however these computations can fortunately be shared between calls to the webservice. In effect - we only need to do the computations once, and all later calls can get the benefit. However, since WCF has no shared application state it seems logical to set WCF in single-instance mode. (Each client would require some of the computations in all likelyhood, forcing us to recompute them per-serssion which could be ok, or per-call which is untenable) However, I am not

ExecuteNonQuery inside loop

我只是一个虾纸丫 提交于 2019-11-29 07:04:25
I'm trying to insert a database record inside a loop in C#. It works when I hard code the values like this: string query3 = "INSERT INTO furniture (room_id,member_id) VALUES (222,333);"; SqlCommand cmd3 = new SqlCommand(query3, sqlConnection3); sqlConnection3.Open(); for (int i = 0; i < arrItemsPlanner.Length; i++) { try { cmd3.ExecuteNonQuery(); } catch { return "Error: Item could not be saved"; } finally { //Fail } } But when I use parameterised queries it doesn't work - even if I hard code a value into the parameterised query like this: string query3 = "INSERT INTO furniture (room_id,member