<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>youdidwhatwithtsql.com &#187; Database Integration</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/database-integration/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Wed, 01 Sep 2010 17:02:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Executing MySQL Stored Procedures from SQL Server</title>
		<link>http://www.youdidwhatwithtsql.com/executing-mysql-stored-procedures-from-sql-server/170</link>
		<comments>http://www.youdidwhatwithtsql.com/executing-mysql-stored-procedures-from-sql-server/170#comments</comments>
		<pubDate>Mon, 08 Jun 2009 19:01:25 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Database Integration]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/executing-mysql-stored-procedures-from-sql-server/170</guid>
		<description><![CDATA[If you ever need to call a MySQL procedure from SQL Server it’s fairly simple thanks to ODBC and Linked Servers. This will allow you to reuse any logic already invested in MySQL Stored Procedures saving you from rewriting them. Here&#8217;s a simple example on how you can do it; Create the following procedure in [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/executing-mysql-stored-procedures-from-sql-server/170">Executing MySQL Stored Procedures from SQL Server</a></p>
]]></description>
			<content:encoded><![CDATA[<p>If you ever need to call a <a href="http://www.mysql.com" target="_blank">MySQL</a> procedure from <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> it’s fairly simple thanks to <a href="http://en.wikipedia.org/wiki/Open_Database_Connectivity" target="_blank">ODBC</a> and <a href="http://msdn.microsoft.com/en-us/library/ms188279.aspx" target="_blank">Linked Servers</a>. This will allow you to reuse any logic already invested in <a href="http://dev.mysql.com/doc/refman/5.0/en/stored-routines.html" target="_blank">MySQL Stored Procedures</a> saving you from rewriting them. Here&#8217;s a simple example on how you can do it;</p>
<ul>
<li>Create the following procedure in your MySQL ‘test’ database. </li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p170code4'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1704"><td class="code" id="p170code4"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> <span style="color: #008000;">`test`</span>.<span style="color: #008000;">`usp<span style="color: #008080; font-weight: bold;">_</span>test`</span>$$
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #008000;">`test`</span>.<span style="color: #008000;">`usp<span style="color: #008080; font-weight: bold;">_</span>test`</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>    
	<span style="color: #990099; font-weight: bold;">LANGUAGE SQL</span>
	<span style="color: #990099; font-weight: bold;">DETERMINISTIC</span>
	<span style="color: #990099; font-weight: bold;">SQL SECURITY</span> <span style="color: #990099; font-weight: bold;">INVOKER</span>
	<span style="color: #990099; font-weight: bold;">COMMENT</span> <span style="color: #008000;">'Test Procedure returns the numbers 1-5'</span>
<span style="color: #990099; font-weight: bold;">BEGIN</span>
	<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">1</span>
	<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
	<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">2</span>
	<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
	<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">3</span>
	<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
	<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">4</span>
	<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
	<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">5</span><span style="color: #000033;">;</span>
<span style="color: #009900;">END</span>$$
DELIMITER <span style="color: #000033;">;</span></pre></td></tr></table></div>

<ul>
<li>Configure your <a href="http://www.mysql.com" target="_blank">MySQL</a> Server as a <a href="http://msdn.microsoft.com/en-us/library/ms188279.aspx" target="_blank">Linked Server</a> in <a href="http://msdn.microsoft.com/en-us/library/ms174173.aspx" target="_blank">SSMS</a>. Plenty of guides on the net about this so I won’t repeat it here. Here’s  a <a href="http://www.ideaexcursion.com/2009/02/25/howto-setup-sql-server-linked-server-to-mysql/" target="_blank">good one</a>. </li>
</ul>
<p>If you get the following message&#160;&#160; </p>
<pre>Msg 7411, Level 16, State 1, Line 1
Server 'MYSQL' is not configured for RPC.</pre>
<p>You need to change the <a href="http://msdn.microsoft.com/en-us/library/ms188279.aspx" target="_blank">Linked Server</a> property &quot;RPC Out&quot; to true.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/06/image9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Linked Server Properties - Enable RPC Out" border="0" alt="Linked Server Properties - Enable RPC Out" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/06/image-thumb9.png" width="539" height="484" /></a></p>
<ul>
<li>Once your <a href="http://msdn.microsoft.com/en-us/library/ms188279.aspx" target="_blank">Linked Server</a> has been configured correctly you’re ready to go. Execute the following <a href="http://msdn.microsoft.com/en-us/library/ms189826.aspx" target="_blank">T-SQL</a> in <a href="http://msdn.microsoft.com/en-us/library/ms188279.aspx" target="_blank">SSMS</a>. </li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p170code5'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1705"><td class="code" id="p170code5"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'CALL test.usp_test()'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AT</span> MYSQL;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/06/image10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Executing MySQL Stored Procedures from SQL Server" border="0" alt="Executing MySQL Stored Procedures from SQL Server" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/06/image-thumb10.png" width="169" height="160" /></a> </p>
<p>In fact the <a href="http://msdn.microsoft.com/en-us/library/aa175921(SQL.80).aspx" target="_blank">EXEC</a> can be used to run any <a href="http://www.mysql.com" target="_blank">MySQL</a> specific command. All the following will work;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p170code6'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1706"><td class="code" id="p170code6"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SHOW TABLES'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AT</span> MySQL; <span style="color: #008080;">-- Show the tables in the current database</span>
<span style="color: #0000FF;">EXEC</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SHOW SLAVE STATUS'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AT</span> MySQL; <span style="color: #008080;">-- Show Slave status info (if applicable)</span>
<span style="color: #0000FF;">EXEC</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SHOW DATABASES'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AT</span> MySQL; <span style="color: #008080;">-- Show the accessible databases</span>
<span style="color: #0000FF;">EXEC</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SHOW CREATE TABLE mysql.user'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AT</span> MySQL; <span style="color: #008080;">-- Show the SQL used to create mysql.users</span></pre></td></tr></table></div>

<p><a href="http://www.mysql.com" target="_blank">MySQL</a> <a href="http://msdn.microsoft.com/en-us/library/ms188279.aspx" target="_blank">Linked Servers</a> work pretty solidly with <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> and allow complex integrations between systems to happen reasonably easily. So if your needs are simple there’s no need to resort to an additional layer like <a href="http://msdn.microsoft.com/en-us/library/ms141026.aspx" target="_blank">SSIS</a> if it’s going to complicate your environment.</p>
<p><map name='google_ad_map_170_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/170?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_170_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=170&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fexecuting-mysql-stored-procedures-from-sql-server%2F170' title="Executing MySQL Stored Procedures from SQL Server" alt=" Executing MySQL Stored Procedures from SQL Server" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/executing-mysql-stored-procedures-from-sql-server/170">Executing MySQL Stored Procedures from SQL Server</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/executing-mysql-stored-procedures-from-sql-server/170/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
