Tag: c#

Insert values into multiple SQL tables

What is a good method to insert table data that replies on many tables in C# and SQL server? So for example say I have the following tables: Products: PK=PID, Product_Name Build: PK:BID, Build_Number, FK:PID Files: PK:FID, File_Name, FK:PID FileDetails: PK:FDID, FK:FID, FK:BID, File_Size, File_Version So all the Primary Keys are auto incremented numbers So […]

Create SQL Server Alias Using WMI on x64

I have a small app which automatically creates necessary SQL Server Alias entries for some servers. The bulk of the code looks like this: private static void SetAlias(string aliasName, string server, string protocol, int? port) { var scope = new ManagementScope(@”\\.\root\Microsoft\SqlServer\ComputerManagement10″); try { scope.Connect(); } catch { scope = new ManagementScope(@”\\.\root\Microsoft\SqlServer\ComputerManagement”); } var clientAlias = […]

Checking a data conforms to a list of rules

I’m interested in understanding if there is a common technique/pattern for checking data in a database conforms to a set of rules. I’m interested, perhaps, in running a service/job each night that churns through the data and raises exceptions to rules. I would quite like the system to be dynamic, i.e. it’s quite easy to […]

Optimizing Importing of Data to SQL Server 2005 with C#

I have a table that has about 1/2 million records in it. Each month we get about 1/2 million more records to import. These are currently shoved into another table in the DB, but will eventually be loaded directly from a txt file. For each of these new records, I have to determine if we […]

Updating/Saving to a SQL Database using C#?

I can’t find how to do this on google anywhere. How do you save to a SQL DB using just C# code? Is it possible? The save method that comes default when you create a DB using the wizard dosen’t actually save the DB: this.Validate(); this.studentsBindingSource.EndEdit(); this.studentsTableAdapter.Update(this.studentsDataSet.FirstClass);

Trouble using my stored procedure

I have the following method that is supposed to be a generic “Save to SQL” method for my application. protected void EjecutarGuardar(string ProcedimientoAlmacenado, object[] Parametros) { SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings[“ConnectionString”].ConnectionString); SqlCommand Command = Connection.CreateCommand(); Command.CommandType = CommandType.StoredProcedure; foreach (object X in Parametros) { Command.Parameters.Add(X); } Connection.Open(); Command.ExecuteNonQuery(); Connection.Close(); Connection.Dispose(); } I have to pass […]

Change app.config connection string depending on PC

I’m doing a c# course at university, and now I’m beginning linQ to xml, linQ to Sql-Server, etc. I work with the example projects in two PCs (university PC and office PC) Is there an easy way to change connection string (from app.config) at runtime, or designtime (using a constant in main.cs) so I can […]

Regex expression in MS SQL

I do not not know much about Regex, I want to try parsing sting from database according to flowing instructions. I know that I am need to use CLR but for begin I want to learn Regex Data in tables look like create table #tempTBL (opis varchar(40)) go insert into #tempTBL select ‘C 136’ union […]

Sql Connection Problem

I have a sqlconnection problem. i have perfectly connection to sql server when i m using sqldatasource. but when i m try use SqlConnection object throw an exception. string qstring = “Data Source=****;Initial Catalog=**;User ID=**;Password=**”; SqlConnection con = new SqlConnection(qstring); con.Open(); (exception thrown here) exception is : A network-related or instance-specific error occurred while establishing […]

Performance issues with transpose and insert large, variable column data files into SQL Server

I’m currently working on a project where we have a large data warehouse which imports several GB of data on a daily basis from a number of different sources. We have a lot of files with different formats and structures all being imported into a couple of base tables which we then transpose/pivot through stored […]

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