Tag: c#

How to disable comment when using SMO

I am writing a SMO script to export my SQL Server 2016 database to a text file. However the Scripter always prepends this comment before my script: /* ==Scripting Parameters== Source Server Version : Version140 (14.0.600) Source Database Engine Edition : Enterprise Source Database Engine Type : Standalone Target Server Version : Version140 Target Database […]

SQLCLR .NET Error: Object reference not set to an instance of an object

I am currently receiving an error when trying to execute a simple SELECT statement that references an assembly that contains the C# code for the Jaro-Winkler distance algorithm. This is my first time working with SQLCLRs. I am able to run the code successfully below without the additional OR statement Example: SELECT * FROM USERS […]

Create database from backup file using C# on the remote SQL Server

I’ve got a backup of my database. After editing it in my program, it’s a new newDb.bak file(on my PC). How could I restore this new database on the remote SQL Server, if I have the connection string (I know ip, login and password)? Mainly I have to do this only using C# (not the […]

Insert value from combo box to SQL Server

In my DB I have two tables (Employee and Team). The Team table has two columns (ID, TeamName) and it’s displayed in an asp.net page as a dropdown. <asp:DropDownList ID=”team_id” runat=”server” CssClass=”form-control”></asp:DropDownList> From my asp.net page I need to insert a row into the employee table which includes teamID. Below is set team combo box […]

Why is the unique constraint missing when filling the datatable?

I have the following table in SQL server projects id(PK, int, not null) name (varchar(255), not null) public_key_token (varchar(50), null) I have added a unique constraint to the name column using ALTER TABLE dbo.projects ADD CONSTRAINT name_unique UNIQUE (name); which results in a Unique, Non-Clustered index on the table (trusting SSMS). In the code I’m […]

Issues in LINQ to SQL with String Contains Escape seqence of Backspace – C#

I have a table in SQL Serve which contains the following model and values: public class Employee { public int EmpId { get; set; } public string Name { get; set; } } It contains the following values EmpId Name ______________________________ 1 A 2 B 3 C C# code to get the records using .Contains(“A\b”) […]

Inserting a row into Relational database table

I am very new to c# and asp.net mvc. I’m building a HR portal for our company where a user can submit a leave form among other things… So I’m using mssql as the database server and using Entity Frame work to communicate with it. I have 3 entities, user (Containing user details), permissions (the […]

Entity Framework creates a table I don't want

I am using Entity Framework Code First approach to have Data Access in my application. I have a table Web_Documents and a table Web_Profils and a relation table Web_Profil_joint_Documents, all of which I have made POCOs for. My problem is when I added a migration, Entity Framework created an extra relation’s table.Now in my context […]

TSQL: Check if distributor exists before executing sp_dropdistributor

Is there a way to check if the distributor exists before dropping it using this command in T-SQL? exec sp_dropdistributor @no_checks = 1, @ignore_distributor=1 Something like this: If (Distributor Exists) Then exec sp_dropdistributor @no_checks = 1, @ignore_distributor=1 I’m trying to avoid this error that gets generated when I execute that statement and the distributor does […]

How to check linq query result against Sql Server Database for data already exist or not?

I am using active directory for getting all the departsment and filtering distinct departments using linq query, below is my code private static DomainController GetDomainController(string domainpath) { var domainContext = new DirectoryContext(DirectoryContextType.Domain, domainpath); var domain = Domain.GetDomain(domainContext); var controller = domain.FindDomainController(); return controller; } private static MyMethod() { var domainController = GetDomainController(ActiveDirectorySettings.DomainPath); // Lookup the […]

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