Tag: .net

Map foreign key to scalar property

I have 2 tables: Data and AdditionalData. Their relation is 1 to 1-0 (any Data can have 0 or 1 AdditionalData). For main context I have classes: class Data { public long Id {get;set;} // PK public string Name {get;set;} public AdditionalData AdditionalData {get;set;} // can be null } class AdditionalData { public long Id […]

Detect SQLServer features from ADO.net

I have an app that creates SQL tables and enables DATA_COMPRESSION=Page. However, that feature is only available when the Enterprise version of SQLServer is being used. There are times when I would like to use this same code on, for example, a SQLLocalDB SKU. For these cases I would like to skip the DATA_COMPRESSION setting […]

Add multiple SQL values with same parameterized query?

I’m fairly new to SQL and trying to figure out the best way to add some predefined data. I figured out from searching around here that I should used a parameterized command to avoid a sql injection attack which isn’t a huge concern in this case but I would like to avoid the possibility and […]

CREATE FUNCTION failed because T-SQL and CLR types for return value do not match

I have created a .Net assembly that returns a set of records. When I create a function in SQL Server, I get the message CREATE FUNCTION for …failed because T-SQL and CLR types for return value do not match. I am a bit lost, does anyone have a clue what is going wrong? This is […]

ServiceStack OrmLite Include Column in Where Clause but Not Select

Consider the LoyaltyCard database DTO I have below: [Alias(“customer_ids”)] [CompositeIndex(“id_code”, “id_number”, Unique = true)] public class LoyaltyCard { [Alias(“customer_code”)] public int CustomerId { get; set; } [Alias(“id_code”)] public string LoyaltyCardCode { get; set; } [Alias(“id_number”)] public string LoyaltyCardNumber { get; set; } [Alias(“date_issued “)] public DateTime? IssueDate { get; set; } [Alias(“linked_id”)] public bool LinkedId […]

How to search on a table with 50,000 records that are encrypted

I have SQL Server 2012, and I cant migrate to SQL server 2016. I am using encryption, in this way with Entity Framework Code First. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Configuration; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace x.y.Api.Models { [Table(“Tbl_Naturalezas”)] public class Naturalezas: EncryptDecrypt { public Naturalezas() { _locked = true; } […]

how to write a single sql query based on combobox selection?

I have a winform in which user input values through a combobox. I am assigning combobox value to search db. If there is no selection then the SQL server query should not use that column to filter. example – if (string.IsNullOrEmpty(combobox1.text)) { …..Select * from country } else if (combobox1.selectedindex > -1) { ….Select * […]

why get “Cannot read from a closed TextReader”

i have a SQL CLR function that return the Json from a Web Api, here es my code [Microsoft.SqlServer.Server.SqlFunction] public static SqlString Funcion() { SqlString document; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“URL”); request.Method = “GET”; request.ContentLength = 0; request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(receiveStream); document = (SqlString)readStream.ReadToEnd(); […]

How to update data in activitypointer

How do I programatically update the subject in an activepointerbase? I’m getting a message that Create/Update method not allowed in Activity Pointer CRM 2011 I am getting an activitypointer record, and attempting to update it: var activityPointer = xrmServiceContext.ActivityPointerSet.FirstOrDefault(x => x.Id == myGuid); I then attempt to update it: activityPointer.EntityState = EntityState.Changed; organizationService.Update(activityPointer); And I […]

List all MSSQL servers in the network VB.NET

I am building one project which simply lists all the MSSQL servers running in the network using VB.NET. I can get the list using ‘SqlDataSourceEnumerator’ with the reference to .NET version 3.5. My problem is that, ‘SqlDataSourceEnumerator’ is not giving me the list with reference of .NET version 4.5. So in order to run my […]

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