ado.net

i am getting an error Argument 2 may not be passed with ref keyword while using ado.net

前提是你 提交于 2020-01-04 04:38:08
问题 int? t = 0; cmd.Parameters.AddWithValue("@Res", ref t); I get an error in the second line: argument 2 may not be passed with ref keyword. 回答1: You can only pass an argument by reference with ref if the parameter is a ref parameter as well. AddWithValue doesn't have any ref parameters, so you can't use it that way. Note that you have to specify ref when calling a method if a parameter has the ref modifier. So: public void WithRef(ref int x) {} public void WithoutRef(int x) {} ... int y = 0; //

Code First Multiple Foreign Keys for One to Many Relation

丶灬走出姿态 提交于 2020-01-04 02:49:06
问题 I'm running into some problems departing from convention using Entity Framework 6, Code First Fluent API. A classic example is that I have an entity called Software. I don't want the db table to be called Softwares. It should be called Software. But there are a few other departures as well. The problem is, 2 columns are being created for a foreign key where only 1 should be. For example, in my domain, the is a 1:m relationship between SoftwareFiles and Software. (The logic being that there

What gets disposed when SqlCommand.Dispose is called?

人走茶凉 提交于 2020-01-04 02:28:42
问题 In theory since SqlCommand implements IDisposable a SqlCommand object should always be disposed. I personally wrap a using statement around them. However I see lots of code that never disposes of SqlCommand objects without any apparent problems. I understand that finalizers will ultimately be called by garbage collection but since that can take quite a while in most cases (and never in others) why isn't the code crashing due to running out of some resource? In our own code base we have code

SQL Server “Network Path Not Found” Randomly and Infrequently Occurring across Environments

ぃ、小莉子 提交于 2020-01-04 01:38:32
问题 Similar (if not same question as) Network path not found exception encountered randomly, but I have code to reproduce the issue so I want to ask again as it appears to be a real issue independent of hardware and can be reproduced. Here's the error: provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection

Multiple statements in single SqlCommand

我是研究僧i 提交于 2020-01-03 19:28:08
问题 I have a set of sql scripts which I send to SQL server using a SqlCommand object in C#. These scripts create stored procedures and as long as I just create the procedures, everything works finde. If my scripts contain the usual "if exists ... drop XYZ; create procedure XYZ ..." block, I get an error which tells me, that create must be the first statement in a batch. Neither semicolon nor "GO" work as separator. Any hint how to execute such a script using a single SqlCommand? I have expected

How to set XACT_ABORT within ADO.NET

岁酱吖の 提交于 2020-01-03 18:58:41
问题 How can I set XACT_ABORT to ON (or OFF) from within ADO.NET ? 回答1: Execute SET XACT_ABORT ON or SET XACT_ABORT OFF . 回答2: There is no client setting: in SQL As Remus said. SET XACT_ABORT is not a property of the connection, command or transaction and can be set/unset at any time in SQL Code. There is no ado.net options for SET NOCOUNT ON etc. 来源: https://stackoverflow.com/questions/2277254/how-to-set-xact-abort-within-ado-net

Ado.Net - How to use connection pooling?

左心房为你撑大大i 提交于 2020-01-03 18:25:22
问题 .Net allows connection pooling which based on what I've read is simply by adding parameters to App.config The question is, am I suppose to do anything in my code to use the connection pool? In my code I open a connection every time data is needed and I close it as soon as I'm done. Am i suppose to do anything special to reuse connections? 回答1: You don't need to do anything special as long as your connections use the same connection string. Use the connection, close it and will automatically

Sqlite setting the default value in create table

浪尽此生 提交于 2020-01-03 17:22:22
问题 I wrote something like create table if not exists QuickTest ( id integer primary key NOT NULL, a TEXT DEFAULT @0, b TEXT, c TEXT); I get an error on @0. Is there a way to insert parameters here or do i need to hardcode the value in? I typically like using parameters when setting values. 回答1: You have to use string constant or NULL. http://www.sqlite.org/syntaxdiagrams.html#column-constraint The DEFAULT constraint specifies a default value to use when doing an INSERT. The value may be NULL, a

How to specify ApplicationName in NpgSql connection string

梦想与她 提交于 2020-01-03 17:15:14
问题 Is it possible to to specify ApplicationName in NpgSql connection string? The following resource usually helps, but it says nothing in this case: Npgsql connection strings 回答1: ApplicationName works for me - "Server=localhost;Port=5432;User Id=***;Password=***;Database=***;ApplicationName=test" . 回答2: In case there are people who searched for answer to this question, here is the solution: application_name=MyApp will not work for npgsql version 2.2.4.3 (Latest Released 2015-02-05) Change

how to serialize a DataTable to json or xml

一笑奈何 提交于 2020-01-03 08:45:13
问题 i'm trying to serialize DataTable to Json or XML. is it possibly and how? any tutorials and ideas, please. For example a have a sql table: CREATE TABLE [dbo].[dictTable]( [keyValue] [int] IDENTITY(1,1) NOT NULL, [valueValue] [int] NULL, CONSTRAINT [Psd2Id] PRIMARY KEY CLUSTERED ( [keyValue] ASC )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] C# code: string connectionString = "server=localhost;database=dbd;uid=**;pwd=**"; SqlConnection mySqlConnection = new