Connecting to SQL Server in ASP.NET

Please note the instructions below assume you already have a database setup on the SQL Server. Please see the SQL Server support pagesfor instructions on using SQL Server Management Studio to access it and create tables etc.

To manually create a database connection to the SQL Server from code you will need to use the following connection string, ensuring you change the values for catalog, user id and password appropriately:

Data Source=sql-server;Initial Catalog=your_username;User ID=your_username;Password=your_SQLServer_password
string conString = "Data Source=sql-server;Initial Catalog=aaa999;User ID=aaa999;Password=SQLServerPassword"; SqlConnection sqlConn = new SqlConnection(conString); SqlCommand sqlCmd = sqlConn.CreateCommand(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = "SELECT name, room, telephone FROM dbo.people; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = sqlCmd; DataTable dt = new DataTable(); da.Fill(dt);

For security reasons, you should ensure you use a different password for your SQL Server login than you do for other University systems.

Comments are closed.