Progress Monitor for IdealProgrammer.com
Take Swift, Intelligent, Massive, Planned, Loving, Effective (S.I.M.P.L.E.) Action to Transform Self into Ideal
Skip Repetitive Navigational Links
Home
News
Presenters
Register
Contact
Categories
Titles
Converter
Code Samples
C# ASP.NET
C# Console
HTML
JavaScript
SQL Server
VB ASP.NET
VB Console
Please login
C#
Description:
Illustrates using Sql Connection in C# to create a Connection String.
Example Class Main:
using System.Data; using System.Data.SqlClient; using System; public class clsSqlConnectionConnectionString { static SqlConnection con; public void Main() { con = new SqlConnection("Server=.\\SQLEXPRESS;Initial Catalog=master;Integrated Security=SSPI"); con.InfoMessage += new SqlInfoMessageEventHandler(con_InfoMessage); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "PRINT('This is how to create an InfoMessage event')"; cmd.Connection = con; try { con.Open(); cmd.ExecuteNonQuery(); } finally { con.Close(); } Console.ReadLine(); } static void con_InfoMessage(object Sender, SqlInfoMessageEventArgs ev) { foreach (SqlError err in ev.Errors) { Console.WriteLine("Entering InfoMessage Event Handler"); Console.WriteLine("Source- " + err.Source); Console.WriteLine("State- " + err.State); Console.WriteLine("Number- " + err.Number); Console.WriteLine("Procedure- " + err.Procedure); Console.WriteLine("Server- " + err.Server); Console.WriteLine("Message- " + err.Message); Console.WriteLine("Exiting InfoMessage Event Handler"); } } }
Example Class Program:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSharp_Syntax { class Program { static void Main(string[] args) { //DatabaseADONET clsSqlConnectionConnectionString mySqlConnectionConnectionString = new clsSqlConnectionConnectionString(); mySqlConnectionConnectionString.Main(); } } }
Home
News
Presenters
Register
Contact
Categories
Titles
Converter
Code Samples
C# ASP.NET
C# Console
HTML
JavaScript
SQL Server
VB ASP.NET
VB Console