Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (SqlConnection sqlconnection2 = new SqlConnection())
- private void ImportToTempTable()
- {
- this.GetProgramInfoForSQLQuery();
- this.GetInstallFolder();
- string config = this._InstallFolder + @"" + this._Version + @"" + this._brandName + @".exe.config";
- GetInstanceName(config);
- string connStr = "<proprietary conn string parameters>";
- bool ConnSucceeds = false;
- SqlConnection sqlConnection = new SqlConnection();
- StringBuilder errorMessages = new StringBuilder();
- if (!ConnSucceeds)
- {
- try
- {
- sqlConnection.ConnectionString = connStr;
- sqlConnection.Open();
- this.WriteNote("SQL Connection Succeeded");
- this.WriteNote("");
- ConnSucceeds = true;
- }
- catch (Exception ex)
- {
- ProjectData.SetProjectError(ex);
- int num = (int)Interaction.MsgBox((object)(@"Unable to connect to SQL Server:" + sqlConnection.ConnectionString + @"
- Does the " + this._brandName + " Database Live on this Machine?"), MsgBoxStyle.Exclamation, (object)"SQL Connection Error");
- ProjectData.ClearProjectError();
- }
- }
- if (ConnSucceeds)
- {
- string filename = @"C:Program FolderDC_Importsdc_raw.txt";
- try
- {
- StreamReader s = new StreamReader(filename);
- string fileContents = s.ReadToEnd();
- int removeHeader = fileContents.IndexOf('n');
- string contentsNoHeader = fileContents.Substring(removeHeader);
- string contentsFixed = contentsNoHeader.Replace("'", "''");
- string delim = "n";
- string[] Rows = contentsFixed.Split(delim.ToCharArray());
- foreach (string row in Rows)
- {
- string query = @"USE DBName IF (NOT EXISTS (SELECT * FROM tempdb.sys.tables WHERE name LIKE '%#DCImportTable%'))
- BEGIN
- CREATE TABLE #DCImportTable (Main varchar (8000));
- INSERT INTO #DCImportTable (Main) VALUES ('" + row + @"');
- END
- ELSE
- INSERT INTO #DCImportTable (Main) VALUES ('" + row + "');";
- SqlCommand command = new SqlCommand(query, sqlConnection);
- command.ExecuteNonQuery();
- this.WriteNote(row);
- }
- this.WriteNote("Check Table");
- this.WriteNote("");
- }
- catch (SqlException ex)
- {
- for (int i = 0; i < ex.Errors.Count; i++)
- {
- errorMessages.Append("Error n" +
- "Message: " + ex.Errors[i].Message + "n");
- }
- this.WriteNote(errorMessages.ToString());
- sqlConnection.Close();
- this.WriteNote("SQL Connection Terminated");
- }
- }
- else
- {
- this.WriteNote("SQL Login Incorrect");
- sqlConnection.Close();
- this.WriteNote("SQL Connection Terminated");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement