<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Access Easy Tips</title>
	<atom:link href="http://accesstips.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://accesstips.wordpress.com</link>
	<description>A WordPress.com weblog about Microsoft Access Tips and Code Samples</description>
	<lastBuildDate>Sun, 18 Mar 2012 02:17:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='accesstips.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Access Easy Tips</title>
		<link>http://accesstips.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://accesstips.wordpress.com/osd.xml" title="Access Easy Tips" />
	<atom:link rel='hub' href='http://accesstips.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Using Microsoft Access to Manage SQL Azure Database Users and Roles</title>
		<link>http://accesstips.wordpress.com/2011/09/12/using-microsoft-access-to-manage-sql-azure-database-users-and-roles/</link>
		<comments>http://accesstips.wordpress.com/2011/09/12/using-microsoft-access-to-manage-sql-azure-database-users-and-roles/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 03:40:08 +0000</pubDate>
		<dc:creator>Patrick Wood</dc:creator>
				<category><![CDATA[Access Tips]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[database roles]]></category>
		<category><![CDATA[Microsoft Access]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://accesstips.wordpress.com/?p=1707</guid>
		<description><![CDATA[One of the best things about SQL Azure is how easy it is to manage User security. In this article we will show you how you can use Microsoft Access to add individual Users to Database Roles which makes managing User security much easier. The Benefits of Using Flexible Database Roles If you grant and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1707&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
One of the best things about SQL Azure is how easy it is to manage User security. In this article we will show you how you can use Microsoft Access to add individual Users to Database Roles which makes managing User security much easier.
</p>
<p></p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
The Benefits of Using Flexible Database Roles
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
If you grant and deny permissions to individual database Users instead of using Database Roles you will have to grant and deny all the permissions to your database objects over and over again each time you create a Database User. It is much easier and efficient to grant and deny all the permissions just one time to a <a href="http://msdn.microsoft.com/en-us/library/ms189121.aspx">Database Role</a> that you create. Then you just have to add new Users to the Role and all the granted and denied permissions are automatically applied to the User.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
There are a number of additional advantages to using Database Roles. You can create as many Database Roles as you need and you can add as many Users as you need to a Role. You can add Users to more than one Role. This allows you complete control over all the permissions granted to all the Database Users. You can change a Role&#8217;s Permissions at any time and the changes will immediately apply to all Users assigned to the Role. If you no longer want to allow access to a View, you just deny the Role all permissions to the View and immediately all the Database Users that are members of that Role can no longer access that View.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
This is very helpful when you develop an application for multiple users which have differing access and security requirements. You can set up one Role with Permissions for data entry, another for workers in the financial department, and another for managers. Controlling Permissions with Database Roles enables you to make sure the financial information is only accessed by authorized users, and the managers can see the Reports they need.
</p>
<p></p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
Understanding Flexible Database Roles
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Before you begin creating SQL Azure Database Roles there are a few things that you need to know. First, SQL Azure has two types of Database roles: <strong>fixed Database Roles</strong> which have fixed permissions and <strong>flexible Database Roles</strong> which you can create and for which you can grant and deny permissions as you choose. You can learn more about fixed database roles from these articles: <a href="http://technet.microsoft.com/en-us/library/ms189612.aspx">Permissions of Fixed Database Roles (Database Engine)</a> and <a href="http://www.mssqltips.com/sqlservertip/1900/understanding-sql-server-fixed-database-roles/">Understanding SQL Server fixed database roles</a>.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
We will be working with the flexible Database Roles which you create and are able to control the permissions granted and denied to the Role. Using this method you need to create the Role before we work with Permissions. And in this case we will also add users to the Role before granting and denying Permissions.
</p>
<p></p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
How to Create Flexible Database Roles
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The syntax for <a href="http://msdn.microsoft.com/en-us/library/ms187936.aspx">creating a Database Role</a> is <span style="font-family:Courier New,Segoe UI;font-size:11pt;">CREATE ROLE <em>role_name</em> [ AUTHORIZATION <em>owner_name</em> ]</span>. If the optional <span style="font-family:Courier New,Segoe UI;font-size:11pt;font-style:italic;">owner_name</span> is not used the User that created the Role will be the <a href="http://technet.microsoft.com/en-us/library/ms188676.aspx">owner</a> of the Role. Normally I use the SQL Azure Administrator account to create roles so I do not usually bother with the Authorization statement. So the T-SQL we will use with SQL Azure to create the Role looks like this:
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
<span style="font-family:Courier New,Segoe UI;"><br />
<pre class="brush: sql;">
CREATE ROLE MyRoleName
</pre>
</p>
<p></p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
Using a Form to Create Flexible Database Roles
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
That is just about as simple as you can get. But we can also create a simple Form to make it easier to create a new Role. To do this, I added a textbox named &#8220;txtNewRole&#8221; with the label caption &#8220;Enter New Role Name&#8221;. I also added a command button named &#8220;cmdCreateRole&#8221;. After making some improvements to the appearance the form looked like this:
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="text-align:center;">
<img src="http://gainingaccess.net/articleimages/frmCreateRoles.png" alt="Create Roles Form" />
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The code that runs when the &#8220;Create New Role&#8221; button is clicked first Validates there is a value in the txtNewRole text box, builds a SQL Statement and passes it to the ExecSQLAzureSQL Function. The Function returns a value of &#8220;True&#8221; to the Sub if the Role was successfully created or &#8220;False&#8221; if it fails. The Sub then informs us of the success or failure to create the Role.
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p><pre class="brush: vb;">
Private Sub cmdCreateRole_Click()

    Dim strSQL As String

    'Verify a Role name has been entered.
    If Len(Me.txtNewRole &amp; vbNullString) = 0 Then
        MsgBox &quot;Please enter a name for the new Role.&quot;, vbCritical
    Else
        'Create the T-SQL to be passed to SQL Azure.
        strSQL = &quot;CREATE ROLE &quot; &amp; Me.txtNewRole
        
        'Create the new Role.
        If ExecSQLAzureSQL(strSQL) = False Then
            MsgBox &quot;The Role was not created. Please try again.&quot;, vbCritical
        Else
            MsgBox &quot;The Role &quot;&quot;&quot; &amp; Me.txtNewRole &amp; &quot;&quot;&quot; was created.&quot;, vbInformation
        End If
    End If
    
End Sub
</pre></p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
How to Execute T-SQL in SQL Azure Using a Pass-through Query and VBA
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The ExecSQLAzureSQL Function uses a temporary Pass-through query in code to &#8220;pass&#8221; your SQL, without modifying it, directly to the SQL Azure Database specified in the Connection String. This Function can be used any time you need to execute a T-SQL statement in SQL Azure that does not return records. It returns &#8220;True&#8221; if the SQL is executed successfully and &#8220;False&#8221; if it fails. The comments in the Function explain what the code is doing.
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p><pre class="brush: vb;">
'Public Function ExecSQLAzureSQL
'Place this Procedure in a Standard Module.
'Executes the SQL using a Pass-through Query.
'The SQL is executed in the SQL Azure database in the connection string.
'This procedure is for &quot;Action Queries&quot; SQL that does not return records.
'
Public Function ExecSQLAzureSQL(strSQL As String) As Boolean
On Error GoTo ErrHandle

    Dim db As DAO.DATABASE
    Dim qdf As DAO.QueryDef

    ExecSQLAzureSQL = False 'Default Value

    Set db = CurrentDb

    'Create a temporary unnamed Pass-through QueryDef. This is a
    'practice recommended in the Microsoft Developer Reference.
    'The order of each line of code must not be changed or the code will fail.
    Set qdf = db.CreateQueryDef(&quot;&quot;)

    'Use a function that returns the Connection string to the SQL Azure database.
    'Change the obfuscatedFunctionName's name for Security.
    qdf.Connect = obfuscatedFunctionName(&quot;Wb_gR%/PD\-k&amp;yZq~j&amp;gt;l&quot;)

    'Set the QueryDef's SQL as the strSQL passed in to the procedure.
    qdf.SQL = strSQL

    'ReturnsRecords must be set to False if the SQL does not return records.
    qdf.ReturnsRecords = False

    'Execute the Pass-through query.
    qdf.Execute dbFailOnError

    'If no errors were raised the query was successfully executed.
    ExecSQLAzureSQL = True

ExitHere:
    'Cleanup for security and to release memory
    On Error Resume Next
    Set qdf = Nothing
    Set db = Nothing
    Exit Function

ErrHandle:
    MsgBox &quot;Error &quot; &amp; Err.Number &amp; vbCrLf &amp; Err.Description _
    &amp; vbCrLf &amp; &quot;In procedure ExecSQLAzureSQL&quot;
    Resume ExitHere

End Function</pre></p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
How to Get the Connection String to a SQL Azure Database
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The obfuscatedFunctionName Function returns the Connection String. The SQL is executed in the SQL Azure Database specified in the Connection String: <span style="font-family:Courier New,Segoe UI;">&#8220;DATABASE=MySQLAzureDatabaseName;&#8221;</span>.
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p><pre class="brush: vb;">
'It is best to change the name of this procedure for better security for your use.
'The strIn Argument value, &quot;Wb_gR%/PD\-k&amp;yZq~j&amp;gt;l&quot;, is used like a Password to keep
'unauthorized users from getting your Connection String. You should also change it
'to suit you before you use it in a distributed application.
Public Function obfuscatedFunctionName(strIn As String) As String
    If strIn = &quot;Wb_gR%/PD\-k&amp;yZq~j&amp;gt;l&quot; Then
        obfuscatedFunctionName = &quot;ODBC;&quot; _
            &amp; &quot;DRIVER={SQL Server Native Client 10.0};&quot; _
            &amp; &quot;SERVER=tcp:MyServerName.database.windows.net,1433;&quot; _
            &amp; &quot;UID=MyUserName@MyServerName;&quot; _
            &amp; &quot;PWD=MyPassword;&quot; _
            &amp; &quot;DATABASE=MySQLAzureDatabaseName;&quot; _
            &amp; &quot;Encrypt=Yes&quot;
    Else
        obfuscatedFunctionName = vbNullString
    End If
End Function
</pre></p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
How to Use a Form to Add a User to a SQL Azure Database Role
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
We can add Users to the Role we have created using the <a href="http://msdn.microsoft.com/en-us/library/ms187750.aspx">sp_addrolemember</a> System Stored Procedure in this manner:
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p><pre class="brush: sql;">
EXEC sp_addrolemember 'MyRoleName', 'MyUserName';
</pre></p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
We can modify the Form we created earlier to add Users to Roles. I added a text box named &#8220;txtRoleName&#8221; and another named &#8220;txtUserName&#8221;. After adding a command button named &#8220;cmdAddUserToRole&#8221; this is how the Form appears:
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="text-align:center;">
<img src="http://gainingaccess.net/articleimages/frmUsersNRoles.png" alt="Manage Users and Roles Form" />
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The following code was added to the cmdAddUserToRole button&#8217;s click event to add the User to the Role:
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p><pre class="brush: vb;">
Private Sub cmdAddUserToRole_Click()

    Dim strRole As String
    Dim strUser As String
    
    'Verify a Role name has been entered.
    If Len(Me.txtRoleName &amp; vbNullString) = 0 Then
        MsgBox &quot;Please enter a name for the Role.&quot;, vbCritical
    Else
        strRole = Me.txtRoleName
        
        'Verify a User name has been entered.
        If Len(Me.txtUserName &amp; vbNullString) = 0 Then
            MsgBox &quot;Please enter a name for the User.&quot;, vbCritical
        Else
            strUser = Me.txtUserName

            'Now that we have both a Role and a User Name we
            'can call a Function to add the User to the Role.
            Call AddUserToSQLRole(strRole, strUser)
        End If
    End If
    
End Sub
</pre></p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
Using a Function to Add a User to a SQL Azure Database Role
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The command button&#8217;s code calls the AddUserToSQLRole Function which we need to place in a Standard Module. This Function passes the necessary T-SQL to the ExecSQLAzureSQL Function we used earlier. One of the basic principles of good programming practice is DRY (Don&#8217;t Repeat Yourself). It is better to write one Procedure that does the same job repeatedly and reliably than it is to write the same code over and over again. Using the DRY principal you write less code and make fewer mistakes. It also makes your code easier to debug, manage, understand, and reuse in other applications.
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p><pre class="brush: vb;">

Function AddUserToSQLRole(strRole As String, strUser As String) As Boolean

    Dim strSQL As String
    
    AddUserToSQLRole = False 'Default Value

    'Build the T-SQL that will add the User to the Role.
    strSQL = &quot;EXEC sp_addrolemember '&quot; &amp; strRole &amp; &quot;', '&quot; &amp; strUser &amp; &quot;';&quot;
    
    'Call the Function to execute the SQL.
    If ExecSQLAzureSQL(strSQL) = True Then
        AddUserToSQLRole = True

        'Inform the User of Success
        MsgBox &quot;User &quot;&quot;&quot; &amp; strUser &amp; &quot;&quot;&quot; was added to the &quot;&quot;&quot; _
            &amp; strRole &amp; &quot;&quot;&quot; Role.&quot;, vbInformation
    Else
        'Inform the User of Failure.
        MsgBox &quot;User &quot;&quot;&quot; &amp; strUser &amp; &quot;&quot;&quot; was NOT added to the &quot;&quot;&quot; _
            &amp; strRole &amp; &quot;&quot;&quot; Role.&quot; &amp; vbCrLf &amp; vbCrLf _
            &amp; Space(30) &amp; &quot;Please try again.&quot;, vbCritical
    End If

End Function
</pre></p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
If your code fails the cause may be a failure to make the connection to SQL Azure. Often the failure may just be an intermittent and temporary issue that can occur for a number of reasons. So it is best to encourage the user to try again because the second attempt will often succeed.
</p>
<p></p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
Summary
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
We have examined how to create SQL Azure Database Roles and add Users to those Roles. We are now prepared to control with precision which users have access to the objects in SQL Azure by using SQL Azure Permissions. We will address that crucial subject in another article.
</p>
<p></p>
<p style="font-family:Verdana,Tahoma;font-weight:bold;font-size:11pt;">
Get the Code
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
You can download the code used in this article from our <a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Free Code Samples page</a>.
</p>
<p></p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;"><b><i>More Free Downloads:</i></b><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Us or UK/AU Pop-up Calendar</a><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Report Date Dialog Form</a> in US or UK/AU Version.<br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Free Church Management Software</a> with Contributions management.<br />
<a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Code Samples</a></p>
<p></p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Get the <a href="http://gainingaccess.net/Products/AppointmentManager.aspx"><strong>Access and Outlook Appointment Manager</strong></a> to manage all of your Outlook Calendar Appointments and Access dated information.</p>
<p></p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Happy computing,<br />
Patrick (Pat) Wood<br />
Gaining Access<br />
<a href="http://gainingaccess.net/"><span style="color:#0055ff;">http://gainingaccess.net</span></a></span></p>
<p></p>
<p style="text-align:center;">
<br />
<a href="#top">Return to Top</a>
</p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:11pt;">
&nbsp;</p>
<br /> Tagged: <a href='http://accesstips.wordpress.com/tag/access-tips/'>Access Tips</a>, <a href='http://accesstips.wordpress.com/tag/database-roles/'>database roles</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access/'>Microsoft Access</a>, <a href='http://accesstips.wordpress.com/tag/sql-azure/'>SQL Azure</a>, <a href='http://accesstips.wordpress.com/tag/vba/'>VBA</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/accesstips.wordpress.com/1707/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/accesstips.wordpress.com/1707/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1707&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://accesstips.wordpress.com/2011/09/12/using-microsoft-access-to-manage-sql-azure-database-users-and-roles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/4f3a0bc9f2f80460d72dba3c67e3a1bc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">easyaccesstips</media:title>
		</media:content>

		<media:content url="http://gainingaccess.net/articleimages/frmCreateRoles.png" medium="image">
			<media:title type="html">Create Roles Form</media:title>
		</media:content>

		<media:content url="http://gainingaccess.net/articleimages/frmUsersNRoles.png" medium="image">
			<media:title type="html">Manage Users and Roles Form</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Create SQL Azure Database Users With Microsoft Access VBA</title>
		<link>http://accesstips.wordpress.com/2011/08/24/how-to-create-sql-azure-database-users-with-microsoft-access-vba/</link>
		<comments>http://accesstips.wordpress.com/2011/08/24/how-to-create-sql-azure-database-users-with-microsoft-access-vba/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 04:07:24 +0000</pubDate>
		<dc:creator>Patrick Wood</dc:creator>
				<category><![CDATA[Access]]></category>
		<category><![CDATA[Access Downloads]]></category>
		<category><![CDATA[Access Tips]]></category>
		<category><![CDATA[Church Management Software]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[free downloads]]></category>
		<category><![CDATA[Microsoft Access]]></category>
		<category><![CDATA[Software development]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[SQL Azure Developer Portal]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Free Access Downloads]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://accesstips.wordpress.com/?p=1691</guid>
		<description><![CDATA[Why do we need a SQL Azure Database User Account? An Access Database cannot access SQL Azure Objects such as Tables, Views, or Stored Procedures without one. That is, unless you use your SQL Azure Administrator account which would be living very dangerously if you were distributing your database to others. So before your database [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1691&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Why do we need a SQL Azure Database User Account?  An Access Database cannot access SQL Azure Objects such as Tables, Views, or Stored Procedures without one. That is, unless you use your SQL Azure Administrator account which would be living very dangerously if you were distributing your database to others. So before your database can do anything with SQL Azure, a Database User Account must be created that it can use. Also permissions must be granted to use the necessary SQL Azure Tables, Views, and Stored Procedures. We are going to show you how you can use a pass-through query in Access to create SQL Azure Database Users using Access VBA.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Database users must be created in the database in which they will exist because the &#8220;USE&#8221; statement can only work for the current database in SQL Azure. So to create a Database User we must use a query that runs in the Database in which we want to create the User. And since it would be confusing, to me at least, to log in using &#8220;JoeDeveloper&#8221; and work as Database User &#8220;SamCodeSlinger&#8221; my normal practice is to create a Database User with the same name as a Login Name.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
If we were using SQL Server Management Studio (SSMS) or the <a href="https://windows.azure.com/">Windows Azure Management Portal</a> we could create a Database User as shown with the following Transact-SQL (T-SQL):
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Courier New;font-size:11pt;margin:5px;">
CREATE USER MyLoginName FOR LOGIN MyLoginName</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
    Or:
</p>
<p style="line-height:14pt;width:95%;font-family:Courier New;font-size:11pt;margin:5px;">
CREATE USER MyLoginName FROM LOGIN MyLoginName
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
But you can easily create Database Users with Microsoft Access using the following two procedures, passing the Login Name to the <span style="font-family:Courier New;font-size:11pt;">CreateSQLAzureDBUser</span> Function:
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p><pre class="brush: vb;">
'Example usage: Call CreateSQLAzureDBUser(&quot;MyLoginName&quot;)
Public Function CreateSQLAzureDBUser(strLoginName As String) As Boolean
On Error GoTo ErrHandle

    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strSQL As String

    CreateSQLAzureDBUser = False 'Default Value

    strSQL = &quot;CREATE USER &quot; &amp; strLoginName &amp; &quot; FOR LOGIN &quot; &amp; strLoginName

    'Create the Database User
    Set db = CurrentDb
    Set qdf = db.CreateQueryDef(&quot;&quot;)
    'Change obfuscatedFunctionName to the name of a Function
    'that Returns your SQL Azure Database Connection String
    qdf.Connect = obfuscatedFunctionName 
    qdf.SQL = strSQL
    qdf.ReturnsRecords = False
    qdf.Execute dbFailOnError

    'If no errors the Database User was Created
    CreateSQLAzureDBUser = True

ExitHere:
    'Cleanup for security and to release memory
    On Error Resume Next
    Set qdf = Nothing
    Set db = Nothing
    Exit Function

ErrHandle:
    MsgBox &quot;Error &quot; &amp; Err.Number &amp; vbCrLf &amp; Err.Description _
    &amp; vbCrLf &amp; &quot;In procedure CreateSQLAzureDBUser&quot;
    Resume ExitHere

End Function
</pre></p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The Database User must be created in the Database in which it is to be used and not in the master Database. You can do this by changing <span style="font-family:Courier New;font-size:11pt;">MySQLAzureDatabaseName</span> in the <span style="font-family:Courier New;font-size:11pt;">obfuscatedFunctionName</span> Function to the name of the database in which you want to create the users.
</p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p><pre class="brush: vb;">
'It is best to change the name of this procedure for better security for your use. 
'The strIn Argument value, &quot;Wb_gR%/PD\-k&amp;yZq~j&gt;l&quot;, is used like a Password to keep 
'unauthorized users from getting your Connection String. You should also change it 
'to suit you before you use it in a distributed application.
Public Function obfuscatedFunctionName(strIn As String) As String

    If strIn = &quot;Wb_gR%/PD\-k&amp;yZq~j&amp;gt;l&quot; Then
        obfuscatedFunctionName = &quot;ODBC;&quot; _
            &amp; &quot;DRIVER={SQL Server Native Client 10.0};&quot; _
            &amp; &quot;SERVER=tcp:MyServerName.database.windows.net,1433;&quot; _
            &amp; &quot;UID=MyUserName@MyServerName;&quot; _
            &amp; &quot;PWD=MyPassword;&quot; _
            &amp; &quot;DATABASE=MySQLAzureDatabaseName;&quot; _
            &amp; &quot;Encrypt=Yes&quot;
    Else
        obfuscatedFunctionName = vbNullString
    End If

End Function
</pre></p>
<p style="line-height:8pt;width:95%;font-family:Times New Roman,Tahoma;font-size:6pt;">
&nbsp;</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
For better security you can keep the Login Name, Password, and User Name hidden in the code without exposing it to the Access user.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
We now have the ability to create Database Users but we still need to Grant Permissions before our Access Database can use this User Account to access any data in SQL Azure. We plan to show how you can do that in the articles to come.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
You can download the code used in this article from our <a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Free Code Samples page</a>.
</p>
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;"><b><i>More Free Downloads:</i></b><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Us or UK/AU Pop-up Calendar</a><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Report Date Dialog Form</a> in US or UK/AU Version.<br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Free Church Management Software</a> with Contributions management.<br />
<a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Code Samples</a></p>
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Get the <a href="http://gainingaccess.net/Products/AppointmentManager.aspx"><strong>Access and Outlook Appointment Manager</strong></a> to manage all of your Outlook Calendar Appointments and Access dated information.</p>
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Happy computing,<br />
Patrick (Pat) Wood<br />
Gaining Access<br />
<a href="http://gainingaccess.net/"><span style="color:#0055ff;">http://gainingaccess.net</span></a></span></p>
<div class="centertxt">
<br />
<a href="#top">Return to Top</a></p>
<br /> Tagged: <a href='http://accesstips.wordpress.com/tag/access/'>Access</a>, <a href='http://accesstips.wordpress.com/tag/access-downloads/'>Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/access-tips/'>Access Tips</a>, <a href='http://accesstips.wordpress.com/tag/database/'>database</a>, <a href='http://accesstips.wordpress.com/tag/free-access-downloads/'>Free Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access/'>Microsoft Access</a>, <a href='http://accesstips.wordpress.com/tag/software/'>Software</a>, <a href='http://accesstips.wordpress.com/tag/sql-azure/'>SQL Azure</a>, <a href='http://accesstips.wordpress.com/tag/sql-server/'>SQL Server</a>, <a href='http://accesstips.wordpress.com/tag/vba/'>VBA</a>, <a href='http://accesstips.wordpress.com/tag/windows-azure/'>Windows Azure</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/accesstips.wordpress.com/1691/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/accesstips.wordpress.com/1691/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1691&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://accesstips.wordpress.com/2011/08/24/how-to-create-sql-azure-database-users-with-microsoft-access-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/4f3a0bc9f2f80460d72dba3c67e3a1bc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">easyaccesstips</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Plug Microsoft Access accde and mde Security Leaks</title>
		<link>http://accesstips.wordpress.com/2011/08/18/how-to-plug-microsoft-access-accde-and-mde-security-leaks/</link>
		<comments>http://accesstips.wordpress.com/2011/08/18/how-to-plug-microsoft-access-accde-and-mde-security-leaks/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 20:21:07 +0000</pubDate>
		<dc:creator>Patrick Wood</dc:creator>
				<category><![CDATA[Access]]></category>
		<category><![CDATA[Access Downloads]]></category>
		<category><![CDATA[Access Tips]]></category>
		<category><![CDATA[Church]]></category>
		<category><![CDATA[Church Management Software]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Free Access Downloads]]></category>
		<category><![CDATA[free downloads]]></category>
		<category><![CDATA[Free Microsoft Access Downloads]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[Microsoft Access]]></category>
		<category><![CDATA[Microsoft Access Software Development]]></category>
		<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software development]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Free Access Tools]]></category>
		<category><![CDATA[Microsoft Access Database]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://accesstips.wordpress.com/?p=1677</guid>
		<description><![CDATA[I was shocked. I had heard that Constants and Variables could be seen by opening an accde or mde file with a hex editor but when I opened my file I was stunned to see so much of my data, objects, and code in plain text. I am not an Access Security expert, but I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1677&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
I was shocked. I had heard that Constants and Variables could be seen by opening an accde or mde file with a hex editor but when I opened my file I was stunned to see so much of my data, objects, and code in plain text. I am not an Access Security expert, but I decided to take on the challenge of this security issue and when I was through I was very pleased with the results. In this article we will examine the security risks of accde and mde files and present some ways you can greatly improve the security of your files.
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:11pt;font-weight:bold;margin:5px;">
The Bad News About accde and mde File Security
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
You don&#8217;t have to be an Access expert to break the security of an Access Database. Anyone can do it with a free hex editor easily downloaded from the internet. The hex editor revealed the data in every local table in my accde database and worse.
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
1) A Simple Hex Editor Reveals Much Information
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Here is a <em>partial</em> list of what I was able to read with a free hex editor:
</p>
<ul>
<li>Names of all Tables both Local and Linked</li>
<li>All Field Names in Local Tables</li>
<li>All Values in Tables Except for Hyperlinks</li>
<li>All Query Names and Query SQL</li>
<li>All Global Constants</li>
<li>All Module Names</li>
<li>All Procedure Names</li>
<li>Most Procedure Arguments</li>
<li>Some Code in Procedures</li>
<li>Usually Two or More Variable Names in Each Procedure</li>
<li>All Form RecordSource Queries and SQL</li>
<li>All Control Names and Property Values</li>
<li>All List Box and Combo Box RowSource Queries and SQL Statements</li>
<li>All References with File Names and Full Paths</li>
</ul>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
I found the code of a couple of procedures virtually intact. As we shall see, this revealed data can lead to even further exploitation.
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
2) Your Forms and Controls are Vulnerable
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
If you have controls on a form that hold sensitive data such as confidential Customer information a user can very easily get that data if they can open the database. A control with the name txtSQLServerConnection may give someone access to the company database. Who knew we were so vulnerable?
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
3) Those Who Know How Can Read Your Constants and Run Your Procedures
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
For those who know how, it is very easy to read your Constants and run your Subs and Functions. I will not reveal how it is done here, but for experienced developers it is a piece of cake.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
I know of no way of safeguarding your Constants short of encrypting your database and that option is not always available. So I think it best not to use Constants for any <em>sensitive data</em> like Connection Strings or Passwords.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Most procedures can easily be run by those who know how. This can reveal a lot of sensitive data and if you use queries in code your database is especially vulnerable. Your data may easily be read, altered, or deleted. That is depressing enough without going further, so I will share some good news.
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:11pt;font-weight:bold;margin:5px;">
The Good News About accde and mde File Security
</p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
1) Encrypting Your File May Provide Greater Security
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Encrypting your database with a password may provide better protection in keeping unauthorized users from getting information from your database. I wrote &#8220;may provide&#8221; because there are some cases where this does not help. Unfortunately it can&#8217;t keep the authorized users from giving their password to others or taping it on a note on their monitor or trying to hack the database themselves. The security of your database is only as strong as your weakest user. In addition, encrypting a database is not always an option for distributed applications, especially when users have different versions of Access because they can only be opened using the version of Access by which they were encrypted.
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
2) Obfuscate the Names of Procedures, Arguments, and Variables
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Variables strA, strB, etc. are a lot better at concealing important information than strAccountNumber and strPassword. Fortunately your comments all get removed when the accde or mde file is created. So if you don&#8217;t want to purchase software to obfuscate your code for you, you can do it yourself and use comments in your original accdb or mdb file to document your code so you can always know what your code is doing.
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
3) Use a Procedure Argument As a &#8220;Password&#8221;
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
It is so very easy to run the procedures in an accde or mde file once you know how. Give me your unencrypted accde or mde file and I can be running procedures in it in less than 5 minutes without any preparation in advance. So I am not going to share that secret here. But I will share how you can easily foil this type of attack.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
If we can use Passwords to open files then we can use them to protect our code from hackers who would run our procedures. When I write an important procedure I add an additional Argument that is used like a Password. When the Procedure runs it  checks for that Argument and if it is not correct then the Procedure does nothing. The following example shows how this works.
</p>
<p>
<pre class="brush: vb;">
'The PartColorNotes Procedure is named to mislead hackers.
'In this case it returns the SQL Azure Database Connection String
Public Function PartColorNotes(strIn As String) As String

    If strIn = &quot;Wb_gR%/PD\-k&amp;yZq~j&amp;gt;l&quot; Then
        PartColorNotes = &quot;ODBC;&quot; _
            &amp; &quot;DRIVER={SQL Server Native Client 10.0};&quot; _
            &amp; &quot;SERVER=tcp:MyServerName.database.windows.net,1433;&quot; _
            &amp; &quot;UID=MyUserName@MyServerName;&quot; _
            &amp; &quot;PWD=MyPassword;&quot; _
            &amp; &quot;DATABASE=MySQLAzureDatabaseName;&quot; _
            &amp; &quot;Encrypt=Yes&quot;
    Else
        PartColorNotes = vbNullString
    End If

End Function
</pre><br />
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
First, if I was a hacker I could not care less about the PartColorNotes. And I would definitely give up trying to run this procedure long before I discovered the &#8220;Password&#8221; and that is the point. We cannot keep the bad guys totally out of our database but we can make it so difficult to get our information it is not worth the effort. Some good news about this method is that after using my other security measures I did not see any string values in my accde and mdb files so this security measure should be very effective.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Below is a procedure that can produce the &#8220;Passwords&#8221; for your Procedure Arguments and which you can also use to create SQL Azure and SQL Server Passwords.
</p>
<p>
<pre class="brush: vb;">
'---------------------------------------------------------------------------------------
' Procedure : GetPWDCharacters
' Author    : Patrick Wood  http://gainingaccess.net
' Date      : 8/10/2011
' Purpose   : Get Random Characters (These are also safe to use for ODBC Passwords)
' Arguments : lngCount is the number of characters you want returned
' Example   : strPassword = GetPWDCharacters(15) - Returns a string of 15 characters
'---------------------------------------------------------------------------------------
Function GetPWDCharacters(lngCount As Long) As String

    Dim i As Long
    Dim j As Long
    Dim arrCharacters As Variant
    Dim strCharacters As String

    'Build an array of Characters including all letters, numbers, and safe special characters
    arrCharacters = Array( _
         &quot;o&quot;, &quot;S&quot;, &quot;v&quot;, &quot;2&quot;, &quot;y&quot;, &quot;Z&quot;, &quot;I&quot;, &quot;%&quot;, &quot;t&quot;, &quot;x&quot;, &quot;6&quot;, &quot;W&quot;, &quot;q&quot;, &quot;_&quot;, &quot;j&quot;, &quot;u&quot;, _
         &quot;8&quot;, &quot;k&quot;, &quot;L&quot;, &quot;&gt;&quot;, &quot;m&quot;, &quot;C&quot;, &quot;R&quot;, &quot;/&quot;, &quot;P&quot;, &quot;9&quot;, &quot;d&quot;, &quot;h&quot;, &quot;^&quot;, &quot;w&quot;, &quot;B&quot;, &quot;f&quot;, _
         &quot;+&quot;, &quot;Q&quot;, &quot;i&quot;, &quot;E&quot;, &quot;&amp;&quot;, &quot;a&quot;, &quot;X&quot;, &quot;U&quot;, &quot;=&quot;, &quot;g&quot;, &quot;b&quot;, &quot;F&quot;, &quot;$&quot;, &quot;O&quot;, &quot;Y&quot;, &quot;J&quot;, _
         &quot;3&quot;, &quot;0&quot;, &quot;K&quot;, &quot;p&quot;, &quot;~&quot;, &quot;s&quot;, &quot;M&quot;, &quot;4&quot;, &quot;H&quot;, &quot;l&quot;, &quot;#&quot;, &quot;D&quot;, &quot;G&quot;, &quot;N&quot;, &quot;\&quot;, &quot;V&quot;, _
         &quot;c&quot;, &quot;z&quot;, &quot;1&quot;, &quot;5&quot;, &quot;T&quot;, &quot;e&quot;, &quot;7&quot;, &quot;n&quot;, &quot;&lt;&quot;, &quot;A&quot;, &quot;r&quot;)

    'Loop the number of times entered
    For i = 1 To lngCount
        'Get a random number to use with the array
        j = Int((UBound(arrCharacters) - LBound(arrCharacters) + 1) * Rnd + 0)

        'Get a Random character and add it to the string
        strCharacters = strCharacters &amp; arrCharacters(j)
    Next i

    GetPWDCharacters = strCharacters

End Function
</pre><br />
</p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
4) Use SQL Server Or SQL Azure As a Back End
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The <b>only</b> way to secure the data in your tables is to place your tables in a secure back end database such as SQL Azure or the Free Express version of Microsoft SQL Server. SQL Server Express has excellent security features that even meets HIPA security requirements. SQL Server&#8217;s fine grained security features also enable you to Grant and Deny Permissions to SQL Server objects or individual users to Database Roles. And SQL Server Express is free for you to <a href="http://www.microsoft.com/sqlserver/en/us/editions/express.aspx">download</a> and distribute.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
There is no foolproof way to keep data stored in Access tables secure. Nothing I did could keep the table values from being read as plain text in a hex editor. Even if you did go through the trouble of encrypting your data before storing it in your tables, it is still too easy for someone to delete or change your data. That is why it is so great to have the free Express versions of SQL Server available to us.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
If you are using SQL Azure or SQL Server linked tables in Access you can write a function that returns the Connection String such as the PartColorNotes Function above. This enables you to safely use code to access your tables. To avoid the security risks involved with using ODBC linked tables see my article entitled <a href="http://gainingaccess.net/SQLAzure/SQLAzureSecurity1.aspx">Building Safer SQL Azure Cloud Applications with Microsoft Access</a>.
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
5) Decompile Your Database Immediately Before Creating Your accde or mde File
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
This is a very crucial step. This did more to keep my sensitive information from being read with a hex editor than anything else I tried, with the exception of encrypting the database with a Password. This is most effective if you use linked tables for important information which prevents a hex editor from reading the table values.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Databases need to be Decompiled because Compacting and Repairing does not remove all the old code you no longer use. It leaves behind a large amount of sensitive information that can be exploited. I found that Decompiling my database and then immediately creating an accde or mde file removed a huge amount of text, code, and other sensitive information from my file. This was so effective it restored my faith in using accde and mde databases.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Decompiling your database should be the last step you take before creating the accde or mde file. FMS provides an  <a href="http://www.fmsinc.com/MicrosoftAccess/Errors/Bad_DLL_Calling_Convention.asp">article with instructions</a> that shows you how to decompile your database as well as create a shortcut that makes decompiling much easier. After decompiling your database it will usually be much smaller and less likely to have unexplained errors.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Decompiling is however an undocumented and unsupported feature so to be safe you should never decompile without making a backup copy first. It is best to keep your original file in a safe place and decompile the copy of the database.
</p>
<p></p>
<p style="line-height:25pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
Summary
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
We have looked at some of the serious security issues with accde and mde files and have presented a number of steps to greatly improve the security of your databases. You should now be able to distribute your accde and mde files with greater confidence in their security.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
You can download the code used in this article from our <a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Free Code Samples page</a>.
</p>
<p></p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
<strong>Get the free <a href="http://gainingaccess.net/SQLAzure/SADownloads.aspx">Demonstration Application</strong></a> that shows how effectively Microsoft Access can use SQL Azure as a back end.
</p>
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;"><b><i>More Free Downloads:</i></b><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Us or UK/AU Pop-up Calendar</a><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Report Date Dialog Form</a> in US or UK/AU Version.<br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Free Church Management Software</a> with Contributions management.<br />
<a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Code Samples</a></p>
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Get the <a href="http://gainingaccess.net/Products/AppointmentManager.aspx"><strong>Access and Outlook Appointment Manager</strong></a> to manage all of your Outlook Calendar Appointments and Access dated information.</p>
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Happy computing,<br />
Patrick (Pat) Wood<br />
Gaining Access<br />
<a href="http://gainingaccess.net/"><span style="color:#0055ff;">http://gainingaccess.net</span></a></span></p>
<p></p>
<p style="text-align:center;">
<a href="#top">Return to Top</a>
</p>
<p style="line-height:14pt;width:95%;font-family:Verdana,Tahoma;font-size:10pt;">
&nbsp;</p>
<br /> Tagged: <a href='http://accesstips.wordpress.com/tag/access/'>Access</a>, <a href='http://accesstips.wordpress.com/tag/access-downloads/'>Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/access-tips/'>Access Tips</a>, <a href='http://accesstips.wordpress.com/tag/code/'>Code</a>, <a href='http://accesstips.wordpress.com/tag/database/'>database</a>, <a href='http://accesstips.wordpress.com/tag/free-access-downloads/'>Free Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/free-access-tools/'>Free Access Tools</a>, <a href='http://accesstips.wordpress.com/tag/free-microsoft-access-downloads/'>Free Microsoft Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access/'>Microsoft Access</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access-database/'>Microsoft Access Database</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access-software-development/'>Microsoft Access Software Development</a>, <a href='http://accesstips.wordpress.com/tag/programming/'>Programming</a>, <a href='http://accesstips.wordpress.com/tag/software/'>Software</a>, <a href='http://accesstips.wordpress.com/tag/software-development/'>software development</a>, <a href='http://accesstips.wordpress.com/tag/sql-azure/'>SQL Azure</a>, <a href='http://accesstips.wordpress.com/tag/sql-server/'>SQL Server</a>, <a href='http://accesstips.wordpress.com/tag/vba/'>VBA</a>, <a href='http://accesstips.wordpress.com/tag/windows-azure/'>Windows Azure</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/accesstips.wordpress.com/1677/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/accesstips.wordpress.com/1677/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1677&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://accesstips.wordpress.com/2011/08/18/how-to-plug-microsoft-access-accde-and-mde-security-leaks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/4f3a0bc9f2f80460d72dba3c67e3a1bc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">easyaccesstips</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Use Microsoft Access to Create Logins in a SQL Azure Database</title>
		<link>http://accesstips.wordpress.com/2011/08/01/how-to-use-microsoft-access-to-create-logins-in-a-sql-azure-database/</link>
		<comments>http://accesstips.wordpress.com/2011/08/01/how-to-use-microsoft-access-to-create-logins-in-a-sql-azure-database/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 18:35:34 +0000</pubDate>
		<dc:creator>Patrick Wood</dc:creator>
				<category><![CDATA[Access]]></category>
		<category><![CDATA[Access Downloads]]></category>
		<category><![CDATA[Access Tips]]></category>
		<category><![CDATA[Church]]></category>
		<category><![CDATA[Church Management Software]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[free Access Add-in]]></category>
		<category><![CDATA[Free Access Downloads]]></category>
		<category><![CDATA[Free Add-in]]></category>
		<category><![CDATA[free Demo]]></category>
		<category><![CDATA[free downloads]]></category>
		<category><![CDATA[Free Microsoft Access Downloads]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[Microsoft Access]]></category>
		<category><![CDATA[Microsoft Access Software Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software development]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[web based]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Free Access Tools]]></category>
		<category><![CDATA[Microsoft Access Database]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://accesstips.wordpress.com/?p=1629</guid>
		<description><![CDATA[In this article we will demonstrate how you can use a Pass-through query in Access with VBA code to create SQL Azure Logins. Microsoft Access can then use the Login and Password to gain access to SQL Azure Tables, Views, and Stored Procedures. We will create a Login using SQL in Access similar to the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1629&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
In this article we will demonstrate how you can use a Pass-through query in Access with VBA code to create SQL Azure Logins. Microsoft Access can then use the Login and Password to gain access to SQL Azure Tables, Views, and Stored Procedures. We will create a Login using SQL in Access similar to the following Transact-SQL (T-SQL):
</p>
<p style="line-height:25pt;width:100%;font-family:Courier New;font-size:10pt;margin:5px;">
CREATE LOGIN MyLoginName WITH password = &#8216;zX/w3-q7jU&#8217;
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Thankfully, a user would never have to memorize that password! Because this Login and password would only be used by my Access application the user never sees it and does not even know it exists.
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
There are several steps involved in creating a Login and Password for SQL Azure. And although most T-SQL that is used in SQL Azure is exactly the same as that used with SQL Server there are some critical differences which we will address in the following steps.
</p>
<p style="line-height:8pt;width:100%;font-size:6pt;">
&nbsp;
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
1) Create a Strong Password that Meets the Requirements of the <a href="http://msdn.microsoft.com/en-us/library/ms161959.aspx">Password Policy</a>.
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
It is very important to use <a href="http://msdn.microsoft.com/en-us/library/ms161962.aspx">Strong Passwords</a> because the extra security is needed since we cannot use Windows Authentication with SQL Azure. Passwords must be at least 8 characters long and contain at least one number or special character such as -/~^&amp;.
</p>
<p style="line-height:8pt;width:100%;font-size:6pt;">
&nbsp;
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
2) Use Characters That Do Not Conflict With ODBC Connection Strings.
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
To avoid errors we should not use these ODBC connection string characters []{}(),;?*!@ in our Login Name and Password.
</p>
<p style="line-height:8pt;width:100%;font-size:6pt;">
&nbsp;
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
3) Build a Transact-SQL Statement Which Will Create the Login.
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
We will use the T-SQL CREATE LOGIN statement in a Pass-through query to create the Login. Since Pass-through queries &#8220;pass&#8221; the SQL unaltered to SQL Azure most of the time the SQL is just like what we would in SQL Server Management Studio (SSMS) and as seen here:
</p>
<p></p>
<p style="line-height:25pt;width:100%;font-family:Courier New;font-size:10pt;margin:5px;">
CREATE LOGIN MyLoginName WITH password = &#8216;zX/w3-q7jU&#8217;
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Another requirement of the CREATE LOGIN statement is that <a href="http://msdn.microsoft.com/en-us/library/ee336268.aspx">it must be the only statement in a SQL batch</a>. So we are only going to create one Login at a time.
</p>
<p style="line-height:8pt;width:100%;font-size:6pt;">
&nbsp;
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
4) Ensure the Login and Password Are Created In the master Database.
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
This is required because <span style="font-family:Courier New;">&#8220;USE master&#8221;</span> does not work in SQL Azure as it does with SQL Server because <b>the USE statement is not supported in SQL Azure</b>. But with Access we can create the Login in the master database by specifying the master database in our Connection String: <span style="font-family:Courier New;font-size:10pt;">&#8220;DATABASE=master;&#8221;</span>. We use a Function like the one below to get the Connection String with an obfuscated name to keep it more secure.
</p>
<p>
<pre class="brush: vb;">
Public Function obfuscatedFunctionName() As String
    obfuscatedFunctionName = &quot;ODBC;&quot; _
	    &amp; &quot;DRIVER={SQL Server Native Client 10.0};&quot; _
	    &amp; &quot;SERVER=tcp:MyServerName.database.windows.net,1433;&quot; _
	    &amp; &quot;UID=MyUserName@MyServerName;&quot; _
	    &amp; &quot;PWD=MyPassword;&quot; _
	    &amp; &quot;DATABASE=master;&quot; _
	    &amp; &quot;Encrypt=Yes&quot;
End Function
</pre><br />
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
See my article <a href="http://gainingaccess.net/SQLAzure/SQLAzureSecurity1.aspx">Building Safer SQL Azure Cloud Applications with Microsoft Access</a> for more information about securing your Access application.
</p>
<p style="line-height:8pt;width:100%;font-size:6pt;">
&nbsp;
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
5) Create a Function to Execute the SQL and Create the Login.
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Place the ExecuteMasterDBSQL Function below in a Standard Module. This Function executes our <span style="font-family:Courier New;font-size:10pt;">CREATE LOGIN</span> statement. It can be used any time you want to execute a T-SQL statement in the SQL Azure master database that does not return records. The Function returns True if the SQL was executed successfully or False if the SQL fails to be executed.
</p>
<p> <br />
<pre class="brush: vb;">
'This procedure executes Action Query SQL in the SQL Azure master database.	
'Example usage: Call ExecuteMasterDBSQL(strSQL) or If ExecuteMasterDBSQL(strSQL) = False Then
'
Function ExecuteMasterDBSQL(strSQL As String) As Boolean
On Error GoTo ErrHandle

    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef

    ExecuteMasterDBSQL = False 'Default Value

    Set db = CurrentDb

    'Create a temporary unnamed Pass-through QueryDef. This is a
    'practice recommended in the Microsoft Developer Reference.
    'The order of each line of code must not be changed or the code will fail.
    Set qdf = db.CreateQueryDef(&quot;&quot;)
    'Use a function to get the SQL Azure Connection string to the master database
    qdf.Connect = obfuscatedFunctionName
    'Set the QueryDef's SQL as the strSQL passed in to the procedure
    qdf.SQL = strSQL
    'ReturnsRecords must be set to False if the SQL does not return records
    qdf.ReturnsRecords = False
    'Execute the Pass-through query
    qdf.Execute dbFailOnError

    'If no errors were raised the query was successfully executed
    ExecuteMasterDBSQL = True

ExitHere:
    'Cleanup for security and to release memory
    On Error Resume Next
    Set qdf = Nothing
    Set db = Nothing
    Exit Function

ErrHandle:
    MsgBox &quot;Error &quot; &amp; Err.Number &amp; vbCrLf &amp; Err.Description _
    &amp; vbCrLf &amp; &quot;In procedure ExecuteMasterDBSQL&quot;
    Resume ExitHere

End Function
</pre></p>
<p style="line-height:8pt;width:100%;font-size:6pt;">
&nbsp;
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;font-weight:bold;margin:5px;">
6) Use a Form to Enter the Login Name and Password
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
We can make it easy for users to create a Login by using a form. To do this we need to add two text boxes and a command button to the form. Both text boxes need to be unbound. Name the text box for the Login Name txtLoginName. Name the text box for the Password txtPassword. Name the command button cmdCreateLogin. The form should look something like this, but without the extra touches for appearance sake.
</p>
<p></p>
<p style="text-align:center;">
<img src="http://gainingaccess.net/articleimages/frmCreateLogin.png" alt="Create Logins Form" />
</div>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Add the code below to the command button&#8217;s Click event. After the code verifies that a Login Name and Password has been entered, it calls the ExecuteMasterDBSQL Function to create the Login in our SQL Azure master database.
</p>
<p>	<br />
<pre class="brush: vb;">
Private Sub cmdCreateLogin_Click()

    'Prepare a Variable to hold the SQL statement
    Dim strSQL As String

    'Build the SQL statement
    strSQL = &quot;CREATE LOGIN &quot; &amp; Me.txtLoginName &amp; &quot; WITH password = '&quot; &amp; Me.txtPassword &amp; &quot;'&quot;

    'Verify both a Login Name and a Password has been entered.
    If Len(Me.txtLoginName &amp; vbNullString) = 0 Then
        'A Login Name has not been entered.
        MsgBox &quot;Please enter a value in the Login Name text box.&quot;, vbCritical
    Else
        'We have a Login Name, verify a Password has been entered.
        If Len(Me.txtPassword &amp; vbNullString) = 0 Then
        	'A Password has not been entered.
        	MsgBox &quot;Please enter a value in the Password text box.&quot;, vbCritical
        Else
        	'We have a Login Name and a Password.
        	'Create the Login by calling the ExecuteMasterDBSQL Function.
	        If ExecuteMasterDBSQL(strSQL) = False Then
	    	    MsgBox &quot;The Login failed to be created.&quot;, vbCritical
	        Else
	    	    MsgBox &quot;The Login was successfully created.&quot;, vbInformation
	        End If
        End If
    End If
End Sub
</pre><br />
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
The code in the Form checks the return value of the ExecuteMasterDBSQL Function and informs us whether or not the Login was successfully created. Once we have created a Login we can create a Database User for the Login and grant the User access to the data in the SQL Azure Database. Creating a Database User for the Login appears to be a good subject for another article.
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
<strong>Get the free <a href="http://gainingaccess.net/SQLAzure/SADownloads.aspx">Demonstration Application</strong></a> that shows how effectively Microsoft Access can use SQL Azure as a back end.
</p>
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;"><b><i>More Free Downloads:</i></b><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Us or UK/AU Pop-up Calendar</a><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Report Date Dialog Form</a> in US or UK/AU Version.<br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Free Church Management Software</a> with Contributions management.<br />
<a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Code Samples</a></p>
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Get the <a href="http://gainingaccess.net/Products/AppointmentManager.aspx"><strong>Access and Outlook Appointment Manager</strong></a> to manage all of your Outlook Calendar Appointments and Access dated information.</p>
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Happy computing,<br />
Patrick (Pat) Wood<br />
Gaining Access<br />
<a href="http://gainingaccess.net/"><span style="color:#0055ff;">http://gainingaccess.net</span></a></span></p>
<br /> Tagged: <a href='http://accesstips.wordpress.com/tag/access/'>Access</a>, <a href='http://accesstips.wordpress.com/tag/access-downloads/'>Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/access-tips/'>Access Tips</a>, <a href='http://accesstips.wordpress.com/tag/code/'>Code</a>, <a href='http://accesstips.wordpress.com/tag/database/'>database</a>, <a href='http://accesstips.wordpress.com/tag/free-access-downloads/'>Free Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/free-access-tools/'>Free Access Tools</a>, <a href='http://accesstips.wordpress.com/tag/free-microsoft-access-downloads/'>Free Microsoft Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access/'>Microsoft Access</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access-database/'>Microsoft Access Database</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access-software-development/'>Microsoft Access Software Development</a>, <a href='http://accesstips.wordpress.com/tag/programming/'>Programming</a>, <a href='http://accesstips.wordpress.com/tag/software/'>Software</a>, <a href='http://accesstips.wordpress.com/tag/software-development/'>software development</a>, <a href='http://accesstips.wordpress.com/tag/sql-azure/'>SQL Azure</a>, <a href='http://accesstips.wordpress.com/tag/sql-server/'>SQL Server</a>, <a href='http://accesstips.wordpress.com/tag/vba/'>VBA</a>, <a href='http://accesstips.wordpress.com/tag/windows-azure/'>Windows Azure</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/accesstips.wordpress.com/1629/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/accesstips.wordpress.com/1629/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1629&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://accesstips.wordpress.com/2011/08/01/how-to-use-microsoft-access-to-create-logins-in-a-sql-azure-database/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/4f3a0bc9f2f80460d72dba3c67e3a1bc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">easyaccesstips</media:title>
		</media:content>

		<media:content url="http://gainingaccess.net/articleimages/frmCreateLogin.png" medium="image">
			<media:title type="html">Create Logins Form</media:title>
		</media:content>
	</item>
		<item>
		<title>Microsoft Access DSN-Less Linked Tables: TableDef.Append or TableDef.RefreshLink?</title>
		<link>http://accesstips.wordpress.com/2011/05/31/microsoft-access-dsn-less-linked-tables-tabledef-append-or-tabledef-refreshlink/</link>
		<comments>http://accesstips.wordpress.com/2011/05/31/microsoft-access-dsn-less-linked-tables-tabledef-append-or-tabledef-refreshlink/#comments</comments>
		<pubDate>Tue, 31 May 2011 18:02:10 +0000</pubDate>
		<dc:creator>Patrick Wood</dc:creator>
				<category><![CDATA[Access]]></category>
		<category><![CDATA[Access Downloads]]></category>
		<category><![CDATA[Access Tips]]></category>
		<category><![CDATA[Church]]></category>
		<category><![CDATA[Church Management Software]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Free Access Downloads]]></category>
		<category><![CDATA[free downloads]]></category>
		<category><![CDATA[Free Microsoft Access Downloads]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[Microsoft Access]]></category>
		<category><![CDATA[Microsoft Access Software Development]]></category>
		<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software development]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[web based]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Free Access Tools]]></category>
		<category><![CDATA[Microsoft Access Database]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://accesstips.wordpress.com/?p=1626</guid>
		<description><![CDATA[When it came to creating DSN-Less Linked Tables I had always used a procedure that deleted the TableDef and appended a new one until a problem occurred. The code I was using to save Linked Tables as DSN-Less Tables was not working with some of the Views in SQL Azure. This was a serious problem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1626&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
When it came to creating DSN-Less Linked Tables I had always used a procedure that deleted the TableDef and appended a new one until a problem occurred. The code I was using to save Linked Tables as DSN-Less Tables was not working with some of the Views in SQL Azure. This was a serious problem because the application I was developing would be distributed to clients who would then distribute it to their clients. We did not want to use a DSN file. But now the code that normally worked without a hitch was failing.
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Because I was developing for SQL Azure, I had to use SQL Azure Security which includes the Username and Password in the Connection string. Even though I explicitly set the dbAttachSavePWD (Enum Value: 131072) when I appended the new TableDefs the Connection Property of my views still did not include my Username and Password. So I quickly wrote some code to loop through the TableDef properties to see if I could discover the problem.
</p>
<p>
<pre class="brush: vb;">
Sub ListODBCTableProps()

    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim prp As DAO.Property
    
    Set db = CurrentDb
    
    For Each tdf In db.TableDefs
        If Left$(tdf.Connect, 5) = &quot;ODBC;&quot; Then
            Debug.Print &quot;----------------------------------------&quot;
            For Each prp In tdf.Properties
                'Skip NameMap (dbLongBinary) and GUID (dbBinary) Properties here
                If prp.Name &lt;&gt; &quot;NameMap&quot; And prp.Name &lt;&gt; &quot;GUID&quot; Then
                     Debug.Print prp.Name &amp; &quot;: &quot; &amp; prp.Value
                End If
            Next prp
        End If
    Next tdf
    
    Set tdf = Nothing
    Set db = Nothing
    
End Sub
</pre><br />
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
I discovered that the TableDef Attributes of the Views for which my code was not working was 536870912 but for the Tables and Views that were working it was 537001984. After checking the TableDefAttributeEnum Enumeration values I was puzzled. The Attributes value for the Views which were not working was 537001984 which is the value for dbAttachedODBC (Linked ODBC database table). And the value of the Attribute for the Tables and Views that were working was 536870912 which is not in the list. After a few moments I figured it out. I saw that if you add the dbAttachedODBC value of 536870912 to the dbAttachSavePWD value of 131072 it equals the 537001984 Attributes value of the DSN-Less Tables and Views that were set properly. This made sense since the documentation Description for dbAttachSavePWD is &#8220;Saves user ID and password for linked remote table&#8221;. Apparently the Views needed both Attributes. But how could I set it?
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Even though my code explicitly set the Attributes value to dbAttachSavePWD when creating the new TableDefs it was not working. Eventually I found some code that used the TableDef.RefreshLink Method, added the TableDefs Attributes dbAttachSavePWD (131072) value, and tested it. This solution worked. Below is the code I used.
</p>
<p>
<pre class="brush: vb;">
Function SetDSNLessTablesNViews() As Boolean

     Dim db As DAO.Database
     Dim tdf As DAO.TableDef
     Dim strConnection As String

     SetDSNLessTablesNViews = False 'Default Value

     Set db = CurrentDb

     'Use a Function to get the Connection string
     'Note: In actual use I never use &quot;Connection&quot; in my Variables or Procedure names.
     'I disguise them to make it hard for a hacker to use code to get my Connection string
     strConnection = GetCnnString()

     'Loop through the TableDefs Collection
     For Each tdf In db.TableDefs
         'Verify the table is an ODBC linked table
         If Left$(tdf.Connect, 5) = &quot;ODBC;&quot; Then
             'Skip System tables
             If Left$(tdf.Name, 1) &lt;&gt; &quot;~&quot; Then
                 Set tdf = db.TableDefs(tdf.Name)
                 tdf.Connect = strConnection
                 If tdf.Attributes &lt; 537001984 Then
                     tdf.Attributes = dbAttachSavePWD 'dbAttachSavePWD = 131072
                 End If
                 tdf.RefreshLink
             End If
         End If
     Next tdf

     SetDSNLessTablesNViews = True

     Set tdf = Nothing
     Set db = Nothing

End Function
</pre><br />
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
I felt better about using the tdf.RefreshLink Method rather than deleting the TableDefs and appending them again. I read that you could delete your TableDefs and not be able to append a new one if there is an error in the Connection string at <a href="http://www.accessmvp.com/DJSteele/DSNLessLinks.html">this page</a> on Doug Steele&#8217;s website at the bottom of the page.
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
I found an interesting <a href="http://www.accessmonster.com/Uwe/Forum.aspx/access/16775/Link-table-in-code-doesn-t-take">discussion</a> about whether to delete and then append a new TableDef or use the RefreshLink Method on Access Monster. However the latest Developer&#8217;s Reference documentation settles the matter for me when it states the TableDef.RefreshLink Method &#8220;Updates the connection information for a linked table (Microsoft Access workspaces only).&#8221;
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
You may also want to see the sample <a href="http://access.mvps.org/access/tables/tbl0009.htm">code</a> from The Access Web by Dev Ashish using the RefreshLink Method.
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Below is an example of the code used to get the Connection string. As I stated in the procedure notes I never use &#8220;Connection&#8221; in Constants, Variables, or Procedure names. Nor do I use cnn, con, cnnString, etc. Instead I disguise the name of my Procedure to make it hard for a hacker to use to get my Connection string. Constants and Procedure names, along with some variables, are easily seen by opening up even an accde or mde file with a free Hex editor unless you have encrypted the database file. If I can see the name of your Constant I can very easily get its value.
</p>
<p>
<pre class="brush: vb;">
'Don't forget to change the name of this procedure
Function GetCnnString() As String

     GetCnnString = &quot;ODBC;&quot; _
         &amp; &quot;DRIVER={SQL Server Native Client 10.0};&quot; _
         &amp; &quot;SERVER=MyServerName;&quot; _
         &amp; &quot;UID=MyUserName;&quot; _
         &amp; &quot;PWD=MyPassW0rd;&quot; _
         &amp; &quot;DATABASE=MySQLDatabaseName;&quot; _
         &amp; &quot;Encrypt=Yes&quot;

End Function
</pre><br />
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
You can see or download the code used in this article from our <a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Free Code Samples</a> page.
</p>
<p></p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
<strong>Get the free <a href="http://gainingaccess.net/SQLAzure/SADownloads.aspx">Demonstration Application</strong></a> that shows how effectively Microsoft Access can use SQL Azure as a back end.
</p>
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;"><b><i>More Free Downloads:</i></b><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Us or UK/AU Pop-up Calendar</a><br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Report Date Dialog Form</a> in US or UK/AU Version.<br />
<a href="http://gainingaccess.net/GainingAccess/FreeDownloads.aspx">Free Church Management Software</a> with Contributions management.<br />
<a href="http://gainingaccess.net/GainingAccess/CodeSamples.aspx">Code Samples</a></p>
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Get the <a href="http://gainingaccess.net/Products/AppointmentManager.aspx"><strong>Access and Outlook Appointment Manager</strong></a> to manage all of your Outlook Calendar Appointments and Access dated information.</p>
</p>
<p style="line-height:14pt;width:100%;font-family:Verdana,Tahoma;font-size:10pt;margin:5px;">
Happy computing,<br />
Patrick (Pat) Wood<br />
Gaining Access<br />
<a href="http://gainingaccess.net/"><span style="color:#0055ff;">http://gainingaccess.net</span></a></span></p>
<br /> Tagged: <a href='http://accesstips.wordpress.com/tag/access/'>Access</a>, <a href='http://accesstips.wordpress.com/tag/access-downloads/'>Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/access-tips/'>Access Tips</a>, <a href='http://accesstips.wordpress.com/tag/code/'>Code</a>, <a href='http://accesstips.wordpress.com/tag/database/'>database</a>, <a href='http://accesstips.wordpress.com/tag/free-access-downloads/'>Free Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/free-access-tools/'>Free Access Tools</a>, <a href='http://accesstips.wordpress.com/tag/free-microsoft-access-downloads/'>Free Microsoft Access Downloads</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access/'>Microsoft Access</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access-database/'>Microsoft Access Database</a>, <a href='http://accesstips.wordpress.com/tag/microsoft-access-software-development/'>Microsoft Access Software Development</a>, <a href='http://accesstips.wordpress.com/tag/programming/'>Programming</a>, <a href='http://accesstips.wordpress.com/tag/software/'>Software</a>, <a href='http://accesstips.wordpress.com/tag/software-development/'>software development</a>, <a href='http://accesstips.wordpress.com/tag/sql-azure/'>SQL Azure</a>, <a href='http://accesstips.wordpress.com/tag/sql-server/'>SQL Server</a>, <a href='http://accesstips.wordpress.com/tag/vba/'>VBA</a>, <a href='http://accesstips.wordpress.com/tag/windows-azure/'>Windows Azure</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/accesstips.wordpress.com/1626/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/accesstips.wordpress.com/1626/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=accesstips.wordpress.com&#038;blog=1286643&#038;post=1626&#038;subd=accesstips&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://accesstips.wordpress.com/2011/05/31/microsoft-access-dsn-less-linked-tables-tabledef-append-or-tabledef-refreshlink/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/4f3a0bc9f2f80460d72dba3c67e3a1bc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">easyaccesstips</media:title>
		</media:content>
	</item>
	</channel>
</rss>
