211
votes
46answers
17k views
What are the pros and cons to keeping SQL in Stored Procs versus Code
What are the advantages/disadvantages of keeping SQL in your C# source code or in Stored Procs? I've been discussing this with a friend on an open source project that we're working on (C# ASP.NET ...
12
votes
1answer
8k views
ExecuteReader requires an open and available Connection. The connection's current state is Connecting
When attempting to connect to MSSQL database via ASP.NET online, I will get the following when two or more people connect simultaneously:
ExecuteReader requires an open and available Connection. ...
169
votes
4answers
153k views
How do I save a stream to a file?
I have a StreamReader object that I initialized with a stream, now I want to save this stream to disk (the stream may be a .gif or .jpg or .pdf).
Existing Code:
StreamReader sr = new ...
25
votes
5answers
129k views
How to execute a stored procedure from c# program
i want to execute this StoredProcedure from c# program How can i do this using c#
Any Help is Greatly Apreciated
I have written the following stored procedure in sqlserver query window and saved it ...
28
votes
7answers
24k views
How to get last inserted id?
I have this code:
string insertSql =
"INSERT INTO aspnet_GameProfiles(UserId,GameId) VALUES(@UserId, @GameId)";
using (SqlConnection myConnection = new SqlConnection(myConnectionString))
{
...
52
votes
16answers
73k views
The underlying provider failed on Open
I was using .mdf for connect to DB and entityClient. Now I want to change the connection string so that there will be no .mdf
Is this connectionString correct
<connectionStrings>
...
5
votes
4answers
2k views
Queuing in OneWay WCF Messages using Windows Service and SQL Server
I need to implement a queuing mechanism for WCF service requests. The service will be called by clients in a one-way manner. These request messages should be stored in a SQL Server database and a ...
27
votes
10answers
20k views
How do I execute a large SQL script (with GO commands) from c#?
I need to execute a large set of sql statements (creating a bunch of tables, views and stored procedures) from within a c# program.
These statements need to be separated by "GO" statements, but ...
17
votes
6answers
84k views
Getting return value from stored procedure in C#
I have the following query:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[Validate]
@a varchar(50),
@b varchar(50) output
AS
SET @Password =
(SELECT Password
FROM ...
8
votes
9answers
8k views
SQL Query slow in .NET application but instantaneous in SQL Server Management Studio
Here is the SQL
SELECT tal.TrustAccountValue
FROM TrustAccountLog AS tal
INNER JOIN TrustAccount ta ON ta.TrustAccountID = tal.TrustAccountID
INNER JOIN Users usr ON usr.UserID = ta.UserID
WHERE ...
156
votes
5answers
103k views
I get a “An attempt was made to load a program with an incorrect format” error on a SQL Server replication project
The exact error is as follows
Could not load file or assembly 'Microsoft.SqlServer.Replication,
Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
or one of its dependencies. ...
4
votes
1answer
3k views
can i use ADFS 2.0 to authenticate certain users against SQL Server
I have been using ADFS to authenticate users against AD fine, using a claims aware template in VS. Some of our users will not be in Active Directory, so i would like to know if its possible to ...
1
vote
3answers
6k views
Return value from SQL Server Insert command using c#
Using C# in Visual Studio, I'm inserting a row into a table like this:
INSERT INTO foo (column_name)
VALUES ('bar')
I want to do something like this, but I don't know the correct syntax:
INSERT ...
45
votes
3answers
20k views
How to catch SQLServer timeout exceptions
I need to specifically catch SQL server timeout exceptions so that they can be handled differently. I know I could catch the SqlException and then check if the message string Contains "Timeout" but ...
101
votes
10answers
77k views
What represents a double in sql server?
I have a couple of properties in C# which are double and I want to store these in a table in SQL Server, but noticed there is no double type, so what is best to use, decimal or float?
This will store ...