All Questions

Tagged with
Filter by
Sorted by
Tagged with
195 votes
28 answers
285k views

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints

I make an outer join and executed successfully in the informix database but I get the following exception in my code: DataTable dt = TeachingLoadDAL.GetCoursesWithEvalState(i, bat); Failed to ...
Anyname Donotcare's user avatar
134 votes
14 answers
245k views

Data is Null. This method or property cannot be called on Null values

I'm working on an application where one can get information on movies from a database as well as add, update and delete the movies. In the database I have three tables (Movie, Genre and MovieGenre <...
holyredbeard's user avatar
  • 20.4k
132 votes
7 answers
308k views

Index (zero based) must be greater than or equal to zero

Hey I keep getting an error: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. My code: OdbcCommand cmd = new OdbcCommand("SELECT FirstName, ...
G Gr's user avatar
  • 6,050
120 votes
6 answers
503k views

How to read SQL Table data into a C# DataTable

I've read a lot of posts about inserting a DataTable into a SQL table, but how can I pull a SQL table into a C#/.NET DataTable?
Will's user avatar
  • 1,337
114 votes
8 answers
151k views

How to get Database Name from Connection String using SqlConnectionStringBuilder

I do not want to split connection strings using string manipulation functions to get Server, Database, Username, and Password. I read the following link and read the accepted answer, I found that is ...
Imran Rizvi's user avatar
  • 7,419
88 votes
15 answers
96k views

EF 4.1 exception "The provider did not return a ProviderManifestToken string"

I am trying to replicate an example found on MSDN. I am using ASP.NET and EF 4.1 (CTP?). I've used NuGet to install the EntityFramework package. I am getting this error: The provider did not return a ...
bugnuker's user avatar
  • 3,938
88 votes
9 answers
31k views

Are Parameters really enough to prevent Sql injections?

I've been preaching both to my colleagues and here on SO about the goodness of using parameters in SQL queries, especially in .NET applications. I've even gone so far as to promise them as giving ...
Rune Grimstad's user avatar
82 votes
9 answers
478k views

Connecting to SQL Server using windows authentication

When I was trying to connect to SQL Server using the following code: SqlConnection con = new SqlConnection("Server=localhost,Authentication=Windows Authentication, Database=employeedetails"); con....
HARI KRISHNA's user avatar
81 votes
6 answers
141k views

Howto? Parameters and LIKE statement SQL

I am writing a searching function, and have thought up of this query using parameters to prevent, or at least limit, SQL injection attacks. However, when I run it through my program it does not ...
Anders's user avatar
  • 12.3k
73 votes
5 answers
37k views

Is there a good LINQ way to do a cartesian product?

I have a class structure like so: Person Dogs (dog 1, dog 2, etc) Puppies (puppy A, puppy B, etc) There is one person. He has 1..n dogs. Each dog has 1..n puppies. I want a list of all the possible ...
Chris's user avatar
  • 40.2k
64 votes
7 answers
124k views

Default port for SQL Server

I need to know the default port settings for the following services SQL Server SQL Browser SQL Reporting services SQL Analysis services I need to know the port settings for these services for ...
balaweblog's user avatar
  • 15.2k
61 votes
12 answers
48k views

The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'

I have a SQL Server 2008 DB with many tables filled with data and I used SQL Server Management Studio to generate a SQL dump by using the Script Wizard : Tasks -> Generate Scripts -> Script All ...
Arunabh Das's user avatar
56 votes
2 answers
56k views

Entering keys manually with Entity Framework

I'm trying to use Entity Framework code first for a simple database project and I run into a problem I simply cannot figure out. I noticed EF was setting the ID for my tables automatically ...
JCafe's user avatar
  • 597
54 votes
5 answers
39k views

Pass table valued parameter using ADO.NET

How to pass table valued parameter to stored procedure using ADO.NET?
NIck's user avatar
  • 563
53 votes
3 answers
23k views

EntityFramework Same Table Many to Many Relationship

I have a table called Products which obviously contains products. However, I need to create related products. So what I've done is create a junction table called product_related which has two PKs. ...
user1027620's user avatar
  • 2,775
46 votes
4 answers
95k views

In memory database in .net [closed]

I have a .net application where i want to use In-Memory data structure. Please advice me how it works in compare to the physical database.
saran's user avatar
  • 1,281
45 votes
1 answer
2k views

ASP.NET Site Maps

Does anyone have experience creating SQL-based ASP.NET site-map providers? I have the default XML file web.sitemap working properly with my Menu and SiteMapPath controls, but I'll need a way for the ...
Zack Peterson's user avatar
44 votes
4 answers
182k views

How to use the ConfigurationManager.AppSettings

I've never used the "appSettings" before. How do you configure this in C# to use with a SqlConnection, this is what I use for the "ConnectionStrings" SqlConnection con = new SqlConnection(); con....
jorame's user avatar
  • 2,187
44 votes
4 answers
56k views

Two foreign keys referencing the same primary key

Is this okay to have two foreign keys in one table referencing one primary key of other table? EmployeeID is a primary key in the employee table and appearing as a foreign key twice in the timesheet ...
user1263981's user avatar
  • 3,059
43 votes
3 answers
311k views

How to convert DataSet to DataTable

I am retrieving data from a SQL table so I can display the result on the page as a HTML table. Later I need to be able to save that table as a CSV file. So far I have figured out how to retrieve the ...
AlwaysANovice's user avatar
42 votes
7 answers
64k views

Connect to AS400 using .NET

I am trying to build a .NET web application using SQL to query AS400 database. This is my first time encountering the AS400. What do I have to install on my machine (or the AS400 server) in order to ...
madatanic's user avatar
  • 1,780
41 votes
8 answers
100k views

How to get the client IP address from SQL Server 2008 itself?

I have a trigger for insert/update/delete. That is working fine. Also, I need the client's IP address from where the changes are made. That I need in T-SQL, that means, not in any web form but in the ...
user avatar
41 votes
10 answers
16k views

Images in database vs file system

We have a project coming up where we will be building a whole backend CMS system that will power our entire extranet and intranet with one package. The question I have been trying to find an answer to ...
Jesse's user avatar
  • 411
36 votes
4 answers
132k views

Nullable DateTime conversion [duplicate]

Possible Duplicate: c# why cant a nullable int be assigned null as a value Im trying to convert my reader[3] object which is datetime to be null if there is no lastPostDate for a Forum but it ...
ONYX's user avatar
  • 5,781
35 votes
11 answers
223k views

Return value using String result=Command.ExecuteScalar() error occurs when result returns null

I want to fetch 1st row 1st cell value from database it works well with below code . But when there is no result found it throws Exception. How to handle with DBNull . Should i change my query ? ...
Satinder singh's user avatar
34 votes
4 answers
141k views

How to use executeReader() method to retrieve the value of just one cell

I need to execute the following command and pass the result to a label. I don't know how can i do it using Reader. Someone can give me a hand? String sql = "SELECT * FROM learer WHERE learer.id = " + ...
javing's user avatar
  • 12.4k
33 votes
3 answers
39k views

Timeout expired with SqlBulkCopy

I'm using SqlBulkCopy to restore tables from xml backups. One of the table backup is ~200MB large and has a lot of records. I'm having error: Timeout expired. The timeout period elapsed prior to ...
HasanG's user avatar
  • 13k
31 votes
6 answers
381k views

Select query to get data from SQL Server

I am trying to run the SQL Select query in my C# code. But I always get the -1 output on int result = command.ExecuteNonQuery(); However, the same table if I use for delete or insert works... ...
user3226440's user avatar
31 votes
7 answers
31k views

sql runs fast in ssms slow in asp.net

I have been having this problem for a couple of weeks now. The problem is that the query takes 4-5 minutes to run on the website and at most 2 or 3 seconds to run in ssms. Also I found that after I ...
Ben's user avatar
  • 393
31 votes
4 answers
33k views

Which is the "best" data access framework/approach for C# and .NET?

(EDIT: I made it a community wiki as it is more suited to a collaborative format.) There are a plethora of ways to access SQL Server and other databases from .NET. All have their pros and cons and it ...
30 votes
10 answers
54k views

Fastest way to retrieve data from database

I am working on a ASP.NET project with C# and Sql Server 2008. I have three tables: Each user has a specific value for each data field, and this value is stored in the DataFieldsValues. Now I ...
enb081's user avatar
  • 3,961
29 votes
10 answers
141k views

System.Data.SqlClient.SqlException: Invalid column name 'phone_types_phone_type_id'

I'm trying to get information from some of my models that have a foreign key relationships to my main employee model. If I map out each model individually, I can access them like normal with no ...
JD Davis's user avatar
  • 3,628
29 votes
4 answers
109k views

Occasionally Getting SqlException: Timeout expired

I have application running on my server. The problem with this application is that daily I am getting nearly 10-20, System.Data.SqlClient.SqlException Timeout expired. The timeout period elapsed prior ...
Imran Qadir Baksh - Baloch's user avatar
28 votes
8 answers
137k views

The wait operation timed out. ASP

I created an internal website for our company. It run smoothly for several months and then I made a major update due to user suggestion. When I run in live, it run normally. Then suddenly one of my ...
Vic's user avatar
  • 477
27 votes
4 answers
46k views

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. in Reference table

I have two tables Customers and Country and use ( Entity Framework with vs 2012 ) And the model class using System; using System.Collections.Generic; public partial class Customer { ...
Ragesh Puthiyedath Raju's user avatar
26 votes
4 answers
42k views

What does "Data Massage" mean?

I am doing some reading, and came across avoiding an internalStore if my application does not need to massage the data before being sent to SQL. What is a data massage?
MrM's user avatar
  • 21.8k
26 votes
4 answers
31k views

What's the difference: Windows Authentication, Passport Authentication and Form Authentication?

Just going to start making a web application and was wondering which was better, or at least what are the main differences between them (as it probably matters what I am using them for)? Windows ...
user avatar
26 votes
9 answers
7k views

User permission error when accessing "user instance" database from ASP.NET

The server hosting csharpindepth.com has recently been migrated. Most of it is working fine, but I can't get at the database used to hold errata, notes etc. Relevant details: 32 bit Windows Server ...
Jon Skeet's user avatar
  • 1.5m
24 votes
14 answers
8k views

What is the Reason large sites don't use MySQL with ASP.NET?

I have read this article from High Scalability about Stack Overflow and other large websites. Many large high traffic .NET sites such as plentyoffish.com, MySpace and Stack Overflow all use .NET ...
Luke101's user avatar
  • 64.3k
24 votes
4 answers
32k views

Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction

Just curious if anyone else has got this particular error and know how to solve it? The scenario is as follow... We have an ASP.NET web application using Enterprise Library running on Windows Server ...
Jimmy Chandra's user avatar
23 votes
2 answers
92k views

C# Invalid attempt to call Read when reader is closed

I am having Invalid attempt to call Read when reader is closed error when I am doing 3 tier project in C# language. What I am trying to do is retrieve address data column by joining two tables ...
user avatar
22 votes
6 answers
160k views

How to save SELECT sql query results in an array in C# Asp.net

How can I save the results of an SQL query into an array? I want to use the values (located in col1 and col2) in an IF statement, leading to my thinking of saving them in an array. var con = new ...
Kamran's user avatar
  • 4,028
21 votes
16 answers
41k views

How can I avoid SQL injection attacks in my ASP.NET application?

I need to avoid being vulnerable to SQL injection in my ASP.NET application. How might I accomplish this?
balaweblog's user avatar
  • 15.2k
21 votes
4 answers
167k views

Selecting multiple columns with linq query and lambda expression

I'm new to C# ASP.NET, and am working on my first application. I'm trying to create a linq statment that return an arrary. I have a table of products. I want to be able to select name, id, and price,...
Mark's user avatar
  • 4,843
21 votes
8 answers
134k views

Using the Web.Config to set up my SQL database connection string?

Can anyone help me out please? I'm confused. I want to set up my connection string so I can just call it from my Web.Config file. I need a way to call it from my code, please make a little example. ...
Sergio Tapia's user avatar
  • 40.7k
20 votes
10 answers
63k views

HTML Encoding in T-SQL?

Is there any function to encode HTML strings in T-SQL? I have a legacy database which contains dodgey characters such as '<', '>' etc. I can write a function to replace the characters but is there ...
Leo Moore's user avatar
  • 2,138
20 votes
2 answers
21k views

.mdf" failed with the operating system error 2(The system cannot find the file specified.)

protected void register_Click(object sender, EventArgs e) { AddUser(userName.Text, password.Text, confirm.Text); } void AddUser(string name, string pass, string confirm) { ...
Erez's user avatar
  • 594
20 votes
3 answers
36k views

How to enable MultipleActiveResultSets

I have the following connection string in my code: SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["RaiseFantasyLeagueConnectionString"].ConnectionString); My ...
JackofAll's user avatar
  • 527
19 votes
5 answers
26k views

ExecuteScalar(); With scope_identity() Generating "System.InvalidCastException: Specified cast is not valid" [duplicate]

I've have a form which accept various data (through textboxes and a checkboxlist) and on the click event they insert all the data into a table and selects the scope_identity then store it in a ...
Mazen Elkashef's user avatar
19 votes
2 answers
35k views

Get byte[] from the SqlDataReader?

I have a table with a varbinary(MAX) parameter. After executing the query, I will store the result in SqlDataReader as it has multiple columns as output. SqlCommand cmd = new SqlCommand("select ...
akshaykumar6's user avatar
  • 2,187

1
2 3 4 5
202