SQL Azure Database Build Fail - Master Key Must Be Created Before DB Scoped Credential - visual-studio

I've imported an Azure SQL DB into VS so i can work in Azure Devops with it.
I'm getting this error when i try to build the DB:
SQL71589: Master Key must be created before a database scoped credential
The DB has a master key, which was created before the user, credential, and external data source which uses it.
I've tried importing into VS with just the master key and no DB Scoped cred, and get no error, then when i create the cred and load it the error comes back. So it seems to be with the creation of the cred.
Also when i click into the error it says there are syntax errors on my cred script, but I've checked against MS docs and it seems fine.
I've tried dropping and recreating in this order the master key, user, credential and external data source.
Seems to be a couple of threads here about this but they haven't helped so far.
I'm using VS 2019 v16.5.4
Any help would be much appreciated.

Open the file that caused the error. Add the creation of Master Key to the top of the file before the Scoped Credential and save it. After the change the content of the file will look like below:
CREATE MASTER KEY ENCRYPTION
BY PASSWORD = '{Your Password}'
GO
CREATE DATABASE SCOPED CREDENTIAL [Your Credential]
WITH IDENTITY = N'SHARED ACCESS SIGNATURE';
Build the project, the build should now be successful.

Related

Azure Storage Explorer - Inadequate resource type access

I am attempting to use the Microsoft Azure Storage Explorer, attaching with a SAS URI. But I always get the error:
Inadequate resource type access. At least service-level ('s') access
is required.
Here is my SAS URI with portions obfuscated:
https://ti<...>hare.blob.core.windows.net/?sv=2018-03-28&ss=b&srt=co&sp=rwdl&se=2027-07-01T00:00:00Z&st=2019-07-01T00:00:00Z&sip=52.<...>.235&spr=https&sig=yD%2FRUD<...>U0%3D
And here is my connection string with portions obfuscated:
BlobEndpoint=https://tidi<...>are.blob.core.windows.net/;QueueEndpoint=https://tidi<...>hare.queue.core.windows.net/;FileEndpoint=https://ti<...>are.file.core.windows.net/;TableEndpoint=https://tid<...>hare.table.core.windows.net/;SharedAccessSignature=sv=2018-03-28&ss=b&srt=co&sp=rwdl&se=2027-07-01T00:00:00Z&st=2019-07-01T00:00:00Z&sip=52.<...>.235&spr=https&sig=yD%2FRU<...>YU0%3D
It seems like the problem is with the construction of my URI/endpoints/connectionstring/etc, more than with permissions granted me on the server, due to the fact that when I click Next, the error displays instantaneously. I do not believe it even tried to reach out to the server.
What am I doing wrong? (As soon as I get this working, I'll be using the URI/etc to embed in my C# app for programmatic access.)
What you need to connect is a service requirement the "SRT" part of the URI.
The URI you have has a SRT of "CO" container and object and needs the "S" part, you need to create a new sas key this can be generated in portal, azure cli or powershell.
In the portal is this part:
You have to enter to the storage acount and select what you need:
Allowed services (if you are looking for blob)
Blob
Allowed resource types
Service (make sure this one is activated)
Container
Object
Allowed permissions (this to do everything)
Read
Write
Delete
List
Add
Create
Example where to look
If you need more info look here:
https://learn.microsoft.com/en-us/rest/api/storageservices/create-account-sas?redirectedfrom=MSDN
If you like to create the SAS key in the CLI use this:
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-user-delegation-sas-create-cli
If you like to create the SAS key in powershell use this:
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-user-delegation-sas-create-powershell
I has a similar issue trying to connect to the blob container using a Shared Access Signature (SAS) URL, and this worked for me:
Instead of generating the SAS URL in Azure Portal, I used Azure Storage Explorer.
Right click the container that you want to share -> "Get Shared Access Signature"
Select the Expiry time and permissions and click create
This URL should work when your client/user will try to connect to the container.
Cheers
I had the same problem and managed to get this to work by hacking the URL and changing "srt=co" to "srt=sco". It seems to need the "s".

No Database Instance in nopcommerce 3.90

I am facing error in nopcommerce 3.90 when run the project at that also at sometimes it is working good but after sometimes it shows the error of "no database instance". I am surprised it shows this type of error. Because the normal thing I have done to run the nopcommerce project.
I have done these things:
set the setting file by installation of nopcommerce.
delete the bin folder of nopcommerce.
clean the solution and rebuild it.
But still facing the same issues.
"no database instance" this type of error occures when the Nopcommerce is not able to connect with the database. If you have created database locally then try to find SQL service and restart the service. But if you are having database being hosted on any other server then check you network connection.
There are some of summery solution that i have mention as below
=> Since i had moved a live cart to a test server, the settings in the database for that cart had force ssl and also force www before any url. Also under Store settings i still had the domain info for that site which was now difrent in the test server. Once i noticed this and updated the database it all started working.
=>
You try change settings.txt file:
DataConnectionString: Data Source=localhost/IP;Initial Catalog=DBName;Integrated Security=False;Persist Security Info=False;User ID=DBUser;Password=DBPass;MultipleActiveResultSets=True
=>
In my case I need config application pool for nopcomerce
my connection string
DataProvider: sqlserver
DataConnectionString: Data Source=.;Initial Catalog=nopcommerce370;Integrated Security=True;Persist Security Info=False
I need set Application Pool Identity to user has access right to db
Check the image to details.
=> Check also db permission.
=> try with
Data Source=9X.2XX.7X.XX\"yoursqlservenameinstance"
or
Data Source="yournamemachine"
or
Data Source="yournamemachine"\"yoursqlservenameinstance"
You can do some thing like
Check setting file on App_data existing or not
Check connectionstring is correct or not
Check your SQL server working or stop by try connect
Clear cache your browser
Try This ``
Right click on the downloaded file (nopCommerce_3.40_Source.rar) ->select properties -> press "Unblock".
and
and change connection string in Settings.txt file.

VS Database Project User Creation Error

I'm trying to publish locally against a SQLExpress instance to test the publish capability of VS Database Project and i"m running into an error where it's trying to create a user that already exists within the database. The user creation isn't being wrapped within an IF EXISTS and I'm not seeing any type of setting to control or enforce this.
Specifically, it's throwing:
Creating [xyz\abc46518]...
(208,1): SQL72014: .Net SqlClient Data Provider: Msg 15063, Level 16, State 1, Line 1 The login already has an account under a different user name.
(208,0): SQL72045: Script execution error. The executed script:
CREATE USER [xyz\abc46518] FOR LOGIN [xyz\abc46518];
While other parts of the script have 'IF EXISTS' and 'IF NOT EXISTS', this part of the script does not.
I'd like to be able to have this as a part of the script to control the users within the database. Should someone choose to grant access and it's not in source, it's going away when we deploy.
I started using database projects, they are great, except for the user permissions.
I only have dba permissions to our databases, whereas handling logins is at the server level.
So when creating the database projects I'd get the following code generated:
CREATE USER [UserName] for login
Which when I went to build the project would error.
Well I wanted the users, but didn't want the hassle of having to keep track of post deployment scripts, largely because they ruined my lovely TFS structure.
My solution, which is a bit of a hack, instead of creating a user, I just created a role with the same name:
CREATE ROLE [UserName]
AUTHORIZATION [dbo];
Now I can assign permissions to the user for my objects (I know all access should be through roles, but its not my database, so I'm happy to hack a fix)
We never deploy roles ourselves, so it doesn't matter to us devs that its a role or a user.

Windows azure cache error - "Cache referred to does not exist. Contact administrator or use the Cache administration tool to create a Cache."

I have one application on Windows Azure cloud and I'm using Windows Azure Co-Located Cache.
Some times, when I publish the website/webservice, this error appears when I call the DataCacheFactory.GetCache method:
Cache referred to does not exist. Contact administrator or use the Cache administration tool to create a Cache.
This problem can go away after few moments, but some times it never fix, then I need to publish projects again.
The stacktrace is:
Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ErrStatus errStatus, Guid trackingId, Exception responseException, Byte[][] payload,
EndpointID destination) at Microsoft.ApplicationServer.Caching.DataCacheFactory.EstablishConnection(IEnumerable`1 servers, RequestBody request, Func`3
sendMessageDelegate, DataCacheReadyRetryPolicy retryPolicy) at Microsoft.ApplicationServer.Caching.SocketClientProtocol.Initialize(IEnumerable`1 servers)
at Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName, CreateNewCacheDelegate cacheCreationDelegate,
DataCacheInitializationViaCopyDelegate initializeDelegate)
See this link whether it can help you...
http://www.windowsazure.com/en-us/develop/net/how-to-guides/cache/#comment-743576866
we were missing the required blob storage container on local
devstorage. After creating the following container :
'cacheclusterconfigs' everything seems to be working now
'cacheclusterconfigs' container will be created by the service internally.you may accidentally deleted that.
Note: IMO please verify the cache name. By default you will be using the cache named 'default'.

Problems with Database Deployment using VS2010 (Package/Publish SQL tab)

Background:
I am using the deployment tools in Visual Studio 2010.
I right clicked my project and selected Package/Publish settings. Put all my settings in there ...
I am then using "web deploy" to tranfer the files to my remote server running a remote agent service and this is working fine. The transforms i have on my Web.Release.config do their thing and the server can access the database I created manually.
Problem:
My next step was to get the Database Deployment working too.
I went into the Package / Publish SQL tab and entered my Connection string for the destination database.
(Data Source=MyDBServer;Initial Catalog=Database2;User ID=User;Password=pass)
This database is empty ready to accept the import.
I also enter in the connection string for the source database. This lives on the same server.
(Data Source=MyDBServer;Initial Catalog=Database;User ID=User;Password=pass)
Database Scripting options are set to Schema and Data (changing this makes no difference) and the database scripts are set to [Auto Generated Schema and Data]
When i deploy this now, i get the error:
Error 4 Web deployment task
failed.((09/06/2010 16:41:51) An error
occurred when the request was
processed on the remote computer.)
(09/06/2010 16:41:51) An error
occurred when the request was
processed on the remote computer. The
entry type 'Unknown' was not expected
at this time. The serialization stream
may be corrupted.
Additional Info:
I can successfully create a package with no problems. I looked at the contents in the zip and can see the SQL is generated fine (so no problems connecting to the database). I can then copy this SQL and run it as a new query on the new database and the tables and data are created fine.
I can not seem to work out where this is going wrong, i googled the error and there are no entries on the whole internet. Anyone have any ideas?
Addendum:
To get some further idea of what might be going on, i sent the package across to the server and imported it using IIS. It told me i needed SQL Server Management Objects. So I installed that.
Next attempt it told me my user did not have permission to create the database, I thought excellent this must be the problem. :Granted access - Re-run. Passed!
So i deleted all the tables and went back to VS2010 clicked publish and i get the same error. :(
Sorted it!
Thank goodness, i was totally out of ideas when i went back to a video by hanselman. He mentioned that the Web Deployment Agent can have permissions. I went in had a look and there was a tab in it's properties called log on.
I entered the detials of an account with a decent level of access and clicked okay.
I then restarted the service as requested to enable the changes.
I then went back to VS 2010 and clicked Publish Web.
Music to my eyes, i see the words "Publish succeeded", I check the database and the tables are there. Excellent!
I think i scared the office by getting a little over excited, if you get this problem and this solution fixes it for you, try to hold in the temptation to shout out "YES!, yes, get in!" while laughing maniacally or people will think you're weird like me.

Resources