Tag: ado.net

TSQL error in .Net but not in SSMS

Having just built a c# application to run SQL scripts, I’ve run into a few issues with error handling. We have a stored procedure in our database which modifies the default constraint for tables (by dropping any existing one and then creating the new one), and it runs fine when we call it from SSMS. […]

Prevent concurrent execution of SQL Server stored procedure with ado.net in Asp.net

I want to prevent two users from executing the same stored procedure concurrently. If two asp.net requests come in to execute that stored procedure, then those should execute in serial manner one after another. SQL Server database and execution is handled by ado.net. Will any of below methods help to achieve this ? What is […]

Inserting Bulk Data in SQL: OLEDB IRowsetFastLoad vs. Ado.Net SqlBulkCopy

I am evaluating different methods for inserting large amount of data in SQL server. I’ve found SqlBulkCopy class from Ado.Net and IRowsetFastLoad interface from OLEDB. As far as I know, IRowsetFastLoad doesn’t map to C#, which is my base platform, so I am evaluating if it would be worth it to create a wrapper around […]

best way to migrate a windows forms application from sql server to oracle

I looking for a best way to migrate a Windows Forms application from MS SQL Server to Oracle. The table schema is recreated in oracle allready and the data was copied into Oracle tables. The App uses ADO.NET Datasets to access the DB. So, should I just kind of replace all references to SqlDataAdapter with […]

compare databases (tables only) using C# and Ado.net

I am trying to develop a software that takes two databases as its input, compares there tables and show differences between tables. This is what I think and develop. 1) Select all the servers that are installed on machine. 2) Depending on the selected server it list all the databases installed. 3) Depending upon the […]

Column does not allow nulls

Please have a look at my code below and tell me where i am going wrong. case “particulars.aspx”: dt = JobCardManager.GetParticularsByJobId(id); hidJobId.Value = id.ToString(); if (dt != null && dt.Rows.Count > 0) { gvParticulars.DataSource = dt; gvParticulars.DataBind(); } else { **dt.Rows.Add(dt.NewRow());** gvParticulars.DataSource = dt; gvParticulars.DataBind(); int TotalColumns = gvParticulars.Rows[0].Cells.Count; gvParticulars.Rows[0].Cells.Clear(); gvParticulars.Rows[0].Cells.Add(new TableCell()); gvParticulars.Rows[0].Cells[0].ColumnSpan = TotalColumns; […]

Batch Update Table Across Non Linked SQL Servers

I am trying to update a table across “non-linked” SQL servers using: C# or VB.net and ADO.net SqlDataAdapter. I need to use DataTable and SqlDataAdapter. Very Important: I need to use BatchUpdate and avoid looping through the DataTable. The table designs in Server 1 differ from table design in Server 2. Source Table: Server 1. […]

How can I create two commands in one connection?

For example I want to INSERT data in database and also UPDATE another table. My code is like this SqlConnection con = new SqlConnection(“**”); con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = “INSERT Borrowbook VALUES (@StudentID, @ISBN, @Title, @Date)”; SqlParameter p1 = new SqlParameter(“@StudentID”, SqlDbType.NChar); p1.Value = textBox2.Text; cmd.Parameters.Add(p1); SqlParameter p2 = new SqlParameter(“@ISBN”, SqlDbType.NVarChar); p2.Value […]

TSQL try catch transaction error handling, transaction count mismatch

I have a sproc that I am calling from C# with a transaction by doing: using (var dbContext = PowerToolsDatabase.GetDataContext()) { dbContext.Connection.Open(); using (dbContext.Transaction = dbContext.Connection.BeginTransaction(System.Data.IsolationLevel.Serializable)) { foreach (var element in package.AddOrUpdateElements) { dbContext.usp_Element_Commit( /* args */); } dbContext.Transaction.Commit(); } } And in that sproc there is a try catch, and a RAISERROR inside the […]

Copy data from one database to another using VB.NET

I need to copy data from one database to another using a VB.NET program. The target database is SQL Server the source database is some proprietary ODBC compliant database. I need to loop through a list of table to copy. Read the data from the source database table for a given modified date. Delete the […]

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