{"id":332,"date":"2019-08-12T13:24:33","date_gmt":"2019-08-12T12:24:33","guid":{"rendered":"https:\/\/blogs.gre.ac.uk\/cmssupport\/?page_id=332"},"modified":"2019-08-12T13:24:33","modified_gmt":"2019-08-12T12:24:33","slug":"connecting-to-mysql-in-visual-studio","status":"publish","type":"page","link":"https:\/\/blogs.gre.ac.uk\/cmssupport\/application-development\/programming\/asp-net\/connecting-to-mysql-in-visual-studio\/","title":{"rendered":"Connecting to MySQL in Visual Studio"},"content":{"rendered":"\n<p>Note the instructions below assume you already have a database setup on the MySQL server. Please see the <a href=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/application-development\/databases\/mysql\/\">MySQL support pages<\/a>\u00a0for details on how to get a MySQL database setup.  <\/p>\n\n\n\n<p>To connect to your MySQL database bring up Server Explorer either by clicking on the tab next to the Toolbox or by going View &gt; Server Explorer. Right click on &#8216;Data Connections&#8217; then click &#8216;Add Connection&#8230;&#8217;<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"425\" height=\"191\" src=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vssqlserver1.png\" alt=\"\" class=\"wp-image-893\" srcset=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vssqlserver1.png 425w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vssqlserver1-300x135.png 300w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vssqlserver1-150x67.png 150w\" sizes=\"auto, (max-width: 425px) 100vw, 425px\" \/><\/figure><\/div>\n\n\n\n<p>On the next screen (titled &#8216;Choose Data Source&#8217;) change the data source by ensuring &#8216;MySQL Database&#8217; is selected, then click the &#8216;Continue&#8217; button.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"518\" height=\"347\" src=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vssqlserver1a.png\" alt=\"Screenshot: Connecting to SQL Server\" class=\"wp-image-906\" srcset=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vssqlserver1a.png 518w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vssqlserver1a-300x201.png 300w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vssqlserver1a-150x100.png 150w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/figure><\/div>\n\n\n\n<p> For the &#8216;Server name&#8217; enter&nbsp;<strong>mysql.cms.gre.ac.uk<\/strong> then enter your username and MySQL password in the relevant fields. When you have entered these correctly you&#8217;ll be able to select your database (mdb_username).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"384\" height=\"380\" src=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql1.png\" alt=\"Screenshot: Connecting to SQL Server\" class=\"wp-image-907\" srcset=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql1.png 384w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql1-300x297.png 300w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql1-354x350.png 354w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql1-150x148.png 150w\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" \/><\/figure><\/div>\n\n\n\n<p> <br>Click the &#8216;OK&#8217; button to exit the &#8216;Add Connection&#8217; wizard and you will have added a connection to the database that will appear under &#8216;Data Connections&#8217; in &#8216;Server Explorer&#8217;, and you can then setup an SQLDataSource using this connection.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"820\" height=\"235\" src=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql2.png\" alt=\"Screenshot: Connecting to SQL Server\" class=\"wp-image-908\" srcset=\"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql2.png 820w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql2-300x86.png 300w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql2-768x220.png 768w, https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-content\/uploads\/sites\/18\/2019\/12\/vsmysql2-150x43.png 150w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/figure>\n\n\n\n<p>\n\nNote that you may need to build your queries manually by picking the &#8216;Specify a custom SQL statement or stored procedure&#8217; option and then building your query manually as Visual Studio will attempt to add elements such as&nbsp;<strong>[<\/strong>&nbsp;(left square bracket) and&nbsp;<strong>]<\/strong>&nbsp;(right square bracket) that will generate errors when processed in MySQL if you use the &#8216;Specify columns from a table or view&#8217; option.<\/p>\n\n\n\n<p>Once you have built your queries you can use them to populate data controls such as a grid view etc.\n\n<\/p>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note the instructions below assume you already have a database setup on the MySQL server. Please see the MySQL support pages\u00a0for details on how to get a MySQL database setup. To connect to your MySQL &hellip;<\/p>\n","protected":false},"author":53,"featured_media":0,"parent":49,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-332","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/332","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=332"}],"version-history":[{"count":0,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/332\/revisions"}],"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=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}