Using Excel as the front end, Azure as the backend - azure

I have a SQL Database on Azure to which I can successfully get connected from within an Excel file. I am using ADO and the connection string uses my own username and password. Since this file will be used by many users, how can I create a generic login and password so that I would not give out my own username and password in the code? The Excel file runs many VBA macros to communicate with the Azure SQL database.
I am using Excel 2010 (yeah, it is old, I have to) and this is my connection string:
mstrConnectionString = "Driver={SQL Server Native Client 11.0};" & _
"Server=tcp:<servername>.database.windows.net,1433;" & _
"Database=<databasename>;" & _
"Uid=<myusername>#<servername>;" & _
"Pwd={MyPassword};" & _
"Encrypt=yes;Connection Timeout=30;"

According your comment, I have an idea that you can create a new login/user for you Azure SQL database.
Then you use this user and password as public account to get or writer data from your Azure SQL database within Excel.
Here's the example T-SQL statement, this code is create a new login and a user in your Azure SQL database. You can run this query in SSMS:
--running in master db
USE [master]
GO
CREATE LOGIN [sagarreadonly] WITH PASSWORD='password'
GO
-- running in Azure SQL DB
USE [DataEncryptDemo]
GO
CREATE USER [sagarreadonly] FOR LOGIN [sagarreadonly] WITH DEFAULT_SCHEMA = Marketing;
GO
EXEC sp_addrolemember 'db_owner', 'sagarreadonly';
GO
The new user is created as 'db_owner' to the specified database.
For more details about database roles, please see Database-Level Roles.
About login and user:
A login is used for user authentication
A database user account is used for database access and permissions
validation.
Logins are associated to users by the security identifier (SID). A login is required for access to the SQL Server server. The process of verifying that a particular login is valid is called "authentication". This login must be associated to a SQL Server database user. You use the user account to control activities performed in the database. If no user account exists in a database for a specific login, the user that is using that login cannot access the database even though the user may be able to connect to SQL Server.
A Login is an identity used to connect to a SQL Server instance. A User allows you to log into a SQL Server database and is mapped to a Login. So you will need to first create a Login, before you can create a User in SQL Server.
Hope this helps.

You can create a "Database login" dialog box to prompt a user for database connection information by using text boxes, buttons, or other dialog box controls. Typically, when you type text in a text box, the text appears as you type. However, you can use a property of the Microsoft Visual Basic for Applications (VBA) Edition User Form to create the effect of a hidden or "masked" text box for creating a password dialog box, where you do not want the text that is typed in a text box to be "visible". Here you will find how to do that.
The information the user types on the "Database login" can be used to build the connection string you posted above.
To create a custom dialog in Excel please follow this instructions.

Related

How to copy an Azure SQL Database to a different server or subscription using Azure Automation

I am trying to copy Azure SQL Database to a different server, and for this I am following this document
[ https://techcommunity.microsoft.com/t5/azure-database-support-blog/how-to-copy-an-azure-sql-database...][1]
I used same credentials for user and login creation at source and destination server. I captured the SID of a user from source server and created a login with the same SID at destination server.
login name: Sana1
username: sanauser
I performed the same steps mentioned in the document for automation account creation. Now, i'm getting below errors with two different scenarios:
1.In the credential tab when i am using Login Name in the user name field -
[image 1 ][2]
In the credential tab when i am using User Name in the user name field -[image 2][3]
thumbnail image 2 of blog post titled
I am not able to connect to destination server to copy database by using above steps. Anyone can help me out with this.
Create a new credential asset with the Azure portal
From your Automation account, on the left-hand pane select
Credentials under Shared Resources.
On the Credentials page, select Add a credential.
In the New Credential pane, enter an appropriate credential name
following your naming standards.
Type your access ID in the User name field.
For both password fields, enter your secret access key.
If the multi-factor authentication box is checked, uncheck it.
Click Create to save the new credential asset.
Note: Azure Automation does not support user accounts that use
multi-factor authentication.
Here is the MSFT Doc with further details.

Azure SQL Contained User. Back-end can't connect using connection string

I followed this guide https://www.mssqltips.com/sqlservertip/5242/adding-users-to-azure-sql-databases/ to create a new user for my back-end API with restricted permissions for basic security reasons but can't make the back-end connect to the server. Every time it tries to connect I'm getting
System.Data.SqlClient.SqlException: 'Login failed for user 'xxxx'.'
I'm able to log-in this new user via SSMS by setting the target database in the login window options.
The back-end can connect just fine with the default connection string supplied by the Azure Portal, witch uses the server admin login. Changing the username and password for the new user, keeping the Initial Catalog to my desired database does not work.
I would assume the back-end would be able to access it since the Initial Catalog property of the connection string is set to the database the contained user was created on. But nothing is working.
This is my connection string used on my back-end:
Server=tcp:xxx.database.windows.net,1433;Initial Catalog=dbName;Persist
Security Info=False;User
ID=newUser;Password=newUserPw;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection
Timeout=30;
I tried many guides but none worked before I found this one that seems to be very knowledgeable about creating Azure SQL users, but even so no luck so far.
This are the commands I used to create the user on the DB I need it to connect(ofc with my own values):
-- select your db in dropdown and create a contained user
CREATE USER [test]
WITH PASSWORD = 'SuperSecret!',
DEFAULT_SCHEMA = dbo;
-- add user to role(s) in db
ALTER ROLE db_datareader ADD MEMBER [test];
ALTER ROLE db_datawriter ADD MEMBER [test];
Anyone knows whats going on? I don't want to have to use my admin login on my back-end.
Turns out the straight answer is to set
Persist Security Info=True;
in the connection string.
When username and password are included in connection string, security-sensitive information such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state unless you set Persist Security info to true.
Reference: Persist Security Info , sqlconnectionstringbuilder

Password reset for Azure database

I have a new Azure account. I am able to log into the 'manage' page as admin, but I forgot the password to one of my databases. I would like to reset the password on that one DB. How do I do that? Microsoft doesn't seem to have a KB on that - at least not one I could find. Thx.
If you're referring to the administrative password for a specific Windows Azure SQL Database server, you can do this from the new portal. Select the Database choice on the left, then select Servers:
Then, after selecting the server of choice, you'll see the option on the right for resetting admin password:
Using the new azure portal:
https://portal.azure.com
Click browse (to view all resources)
Select SQL databases
Choose a database that's in the server you want to change creds for.
Select the server name url for that selected database. This should open up the server configuration blade.
Reset password is the second button from left.
Another variation on new Azure portal (bypassing the database), #1 go to SQL servers directly; #2 click on the DB Server you want to update the password for, #3 click the pencil, #4 update the password, confirm and save.
To reset the administrator password for a SQL Database server, use the following steps:
Go to the Windows Azure Management Portal at http://manage.windowsazure.com and click SQL Databases in the left-hand navigation pane.
Click the Servers tab at the top of the SQL Databases workspace. This will launch the Server List View.
In the Server List View, click the name of the server to update. This will launch the Server Dashboard.
On the Server Dashboard, click Reset Administrator Password under quick glance tasks on the right-hand side of the workspace.
On the Reset Password dialogue, specify a new password and then confirm the new password.
To complete the operation, click the Check mark button at bottom right. You will be returned to the Server Dashboard for the server.
If you reset the SQL Database server password during a time when there are active connections to databases on the server, you may want to use the KILL statement to terminate user sessions. This will force client connections to refresh their sessions with the database and the host server. For more information, see KILL (Windows Azure SQL Database).
With the current iteration of the interface, the process is similar to what is described above with an additional step:
Get to the Overview as described above.
New: Click on the server name (I just had to stumble into it. Horrible UI design.)
Now there is an option to reset the password.
You can use the following command with the Azure CLI 2.0 to change / reset the password for Azure SQL Database:
az sql server update -n {database server name}
-g {resource group name}
-p {password}
Source: https://buildazure.com/2017/05/18/azure-cli-2-0-reset-azure-sql-database-password/
You can actually reset your admin password to your SQL database using the old/previous Silverlight portal.
Log into https://windows.azure.com/ or into the current one and select "Previous portal" from your login
In the previous portal click the "Database" menu item on the bottom left
Select the database from the subscription
click the "reset password"
Update for new portal:
Go to the SQL server that's hosting your SQL DB and click on "Reset password".
If someone had forgotten his password for DB, First of all, look at the connection string(appsettings.json).
You will find it there.

How to access Azure web site's database

I created a Wordpress web site in Azure. Is there anyway to access the database that was set up along with it? (so I can back / or if I should want to Migrate in the future )
If you go to the website dashboard tab, you will see a link call "view connection string". If you click that you will see the connection string with database and server name, user name, and password , etc. You should be able to use those to log into your MySql database using tool such as http://dev.mysql.com/downloads/gui-tools/5.0.html

How can a SharePoint SQL connection be set to query by the current login name?

I have a SQL table that needs to be queried by the login name. So, using SharePoint designer I successfully created a database connection, but I can't use the properties exposed by Profile nor Session as input parameters because they are not supported (A dialog pops up with a message indicating this)
How else can I query a SQL datasource by using the current login?
-Edit
To create the data connection, proceed as follows
Open the data source library
Expand database connections and click on connect to a database
Enter the database settings
Select "specify custom Select, Update, Insert, and Delete"
Click on Edit Command
Add a parameter and select Profile and enter UserName as the property name
An error will follow stating that this is not supported.
Unfortunately, you don't give many details but I think you're looking for the LOGON_USER Server Variable: Data View / Data Form: Parameters You Don’t Know About.

Resources