{"id":339,"date":"2019-08-12T13:47:58","date_gmt":"2019-08-12T12:47:58","guid":{"rendered":"https:\/\/blogs.gre.ac.uk\/cmssupport\/?page_id=339"},"modified":"2024-09-03T16:55:01","modified_gmt":"2024-09-03T15:55:01","slug":"connecting-to-sql-server-in-asp-net","status":"publish","type":"page","link":"https:\/\/blogs.gre.ac.uk\/cmssupport\/application-development\/programming\/asp-net\/connecting-to-sql-server-in-asp-net\/","title":{"rendered":"Connecting to SQL Server in ASP.NET"},"content":{"rendered":"\n<p>Please note the instructions below assume you already have a database setup on the SQL Server. Please see&nbsp;<a href=\"https:\/\/cms-support.gre.ac.uk\/db\/sqlserver.html\">the SQL Server support pages<\/a>for instructions on using SQL Server Management Studio to access it and create tables etc.<\/p>\n\n\n\n<p>To manually create a database connection to the SQL Server from asp.net code you will need to use the following connection string, ensuring you change the values for catalogue, user id and password appropriately:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Data Source=sql-server;Initial Catalog=your_username;User ID=your_username;Password=your_SQLServer_password<br><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">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);<br><\/pre>\n\n\n\n<p>For security reasons, you should ensure you use a different password for your SQL Server login than you do for other University systems.<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Please note the instructions below assume you already have a database setup on the SQL Server. Please see&nbsp;the SQL Server support pagesfor instructions on using SQL Server Management Studio to access it and create tables &hellip;<\/p>\n","protected":false},"author":53,"featured_media":0,"parent":49,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-339","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/comments?post=339"}],"version-history":[{"count":1,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/339\/revisions"}],"predecessor-version":[{"id":2420,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/339\/revisions\/2420"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/49"}],"wp:attachment":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/media?parent=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}