Tag: c#

Encrypting data in SQL Server or C#

I’m looking into on how to encrypt selected user data fields on a web server, and would like suggestions on how to achieve the best results. For an example, say that a user inputs his/her first name, last name, email and social security number; and that: Administrators need to be able to view this information. […]

Stored Procedure providing inconsistent return values

I’m working on a web form that validates data that the user uploads in the form of an Excel file. The code iterates through each row in the spreadsheet and checks against various rules, one of which is that the reference must be a unique value. I have a stored procedure that takes the userID […]

C# : Application doesn't access database in client pc

I have installed sql server in client pc but the app doesn’t access database. this is my connection string : connectionString=”Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\myDB.mdf;Integrated Security=True;User Instance=True” please, is there other apps must be installed in client pc (e.g., SSMS)?

XML assigned to SqlXml parameter got extra-encoded?

The following code passes an XML parameter to a stored procedure. The SqlXml is converted from a string. var range = GetXml(“<Range><Column Name=\”Id\” Low=\”5002\” High=\”8076\” /></Range>”); cmd.Parameters.Add(new SqlParameter(“@Range”, SqlDbType.Xml) { Value = range }); SqlXml GetXml(string s) { var memoryStream = new MemoryStream(); var settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.ConformanceLevel = ConformanceLevel.Fragment; using […]

Is it better to use one or many contexts

We have an application that has 3 contexts for connecting to 3 SQL Server databases, under the same server. Our DBAs are arguing that these three connections are being costly for the server. My question is: is it true? Are three connections more costly than one? How can I measure it? What is the best […]

Save Binary image into SqlServer 2014 from C#

I have a problem with the code c# below, i should save a binary image in a sql server database 2014, i did the function to convert the image to binary, the image select it with a button, The problem is that when I save the database to 0x00 in the field Immagine, how can […]

Custom Validation if textbox is empty but data still to record in database

This My aspx i want when i insert data is not to record in database… <div class=”form-group”> <label for=”description” class=”control-label”>Hazard Description : </label> <div class=”col-xs-8″> <asp:TextBox ID=”TextBox3″ runat=”server” CssClass=”form-control” TextMode=”MultiLine” Columns=”55″ Rows=”7″></asp:TextBox> <asp:CustomValidator ID=”CustomValidatorHazardDescription” ValidateEmptyText=”true” runat=”server” Display=”Dynamic” ErrorMessage=”Tidak Boleh Kosong” OnServerValidate=”CustomValidatorHazardDescription_ServerValidate”></asp:CustomValidator> </div> </div> When I Clik insert message successfull but data still to record in […]

Lambda query translate .count as select rows (EF6 code first)

I have 2 simple tables. Post is the master and has n votes. I want to return posts with their vote count. This is my code: db.posts.Select(p=> new PostlDto{Title= p.Title, VoteCount= p.Votes.Count}) It is ok that I have 1 call to get posts and several calls to get counts. but the problem is that each […]

Parameterize insert of multiple rows

Is there any way to parameterize an SQL INSERT statement (in C#), which inserts multiple rows? Currently I can think of only one way, to generate a statement for inserting mulitple rows, but that is quite open to SQL injection: string sql = ” INSERT INTO my_table” + ” (a, b, c)” + ” VALUES”; […]

Capturing RAISERROR in C#

I tried to find a useful answer to this question, but failed (the closest I found was this). I have a C# app calling a stored procedure which uses SQL TRY/CATCH to handle errors. I can replicate the issue with a sample stored procedure like this: if object_id(‘dbo.TestSQLError’) is not null drop proc dbo.TestSQLError go […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.