3

I followed the WingtipToys tutorial on the Microsoft website, which is basically a tutorial for ASP.NET and shows off numerous features it can do, and so on.

I made my own database to use during the tutorial, and had it working flawlessly on my local machine. Then, I decided to publish it to Azure to see it working online properly, which is where my issues began.

Firstly, I made a SQL database in Azure and moved my database across. I can connect to this Azure database in Visual Studio, and can verify that all the right tables are there, each filled with data;

Database Connection in Visual Studio

Database Data

The next step was to update my connection string, which is currently;

  <connectionStrings>
    <add name="WingtipTpys" providerName="System.Data.SqlClient" connectionString="Server=tcp:xxxx.database.windows.net,1433;Database=xxxx;Integrated Security=False;User Id=xxx;Password=xxxx;Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />
  </connectionStrings>

Now, I was under the impression at this stage that the database and the website could now communicate with each other, so I published the website to see how it looks, which is where the really confusing part (for me) occurs.

When I visit the website URL that I published (http://completebusiness2017.azurewebsites.net/) it uses the right master page, and the about and contact pages are both how they should be. But, it is pulling in data from the;

ProductDatabaseInitializer

Class, which contains code such as;

 private static List<Product> GetProducts()
    {
      var products = new List<Product> {
                new Product
                {
                    ProductID = 1,
                    ProductName = "TEST",
                    Description = "This convertible car is fast! The engine is powered by a neutrino based battery (not included)." + 
                                  "Power it up and let it go!", 
                    ImagePath="",
                    UnitPrice = 39.50,
                    CategoryID = 1
               },
                new Product 
                {
                    ProductID = 2,
                    ProductName = "Silly Car",
                    Description = "There's nothing old about this toy car, except it's looks. Compatible with other old toy cars.",
                    ImagePath="",
                    UnitPrice = 15.95,
                     CategoryID = 1
               },

This class has been there all along, but on my local machine, it was never used. The data came straight from the database I created. I don't understand how now I have updated the connection string, it is pulling data from this class, and not my database. Another strange element, is that when I update this class, so for example I changed;

Convertible Car Price from 22.50 to 39.50 and Old-time Car name to Silly Car

These do not update when the website is published again. So I have no idea where or why it is using the old data.

So I guess my first question is, when I update the ProductDatabaseInitializer class, why aren't these changes reflected when the website is published again? I think I should understand why that is happening before I query why my database isn't working properly.

Any help at all would be very much appreciated.

Thank you, happy holidays.

1 Answer 1

1

I am not 100% convinced that you're pulling data from where you think you are. Can you verify your database connection strings?

You'll need to look in a couple of places. First, in the Azure Portal, navigate to your Web App, then choose the "Application Settings" menu option. Check to see if you have anything listed under your "Connection Strings" section.

Second, log into your SCM site at the address http://completebusiness2017.scm.azurewebsites.net. Once logged in, choose Debug Console -> CMD. Then browse to your /wwwroot folder and examine the web.config file contents. Check to make sure that the connection string listed there is also what you expect.

Note that the App Settings Connection String listed in the portal will take precedence over what's in your web.config file. See if the database you expect to connect to is actually listed in these two places.

Also, log into your SCM site and browse to the /App_Data directory. See if there is a database there that you didn't expect to see.

Sign up to request clarification or add additional context in comments.

7 Comments

On the Azure settings, it has the following connection string; Data Source=tcp:completebusiness2017dbserver.database.windows.net,1433;Initial Catalog=CompleteBusiness2017_db;User Id=Complete1@completebusiness2017dbserver;Password=PasswordHere Which matches what is in the connection string on Visual Studio. It has type "SQL Database".
The SCM site has; ` <connectionStrings> <add name="WingtipTpys" providerName="System.Data.SqlClient" connectionString="Server=tcp:completebusiness2017dbserver.database.windows.net,1433;Database=WINGTIPTOYS;Integrated Security=False;User Id=Complete1;Password=PasswordHere;Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />` As well as <add name="WingtipToys" connectionString="WingtipToys_ConnectionString" providerName="System.Data.SqlClient" /> </connectionStrings> I am not sure what the second connection string is, or why it is there.
Does it matter that in the SCM site, your connection string name is spelled WingtipTpys?
I did not notice that. When I changed it to the correct spelling, it gave me an error that it cannot have two connection strings named the same. So, I renamed the second connection string (the one I don't understand why it's there) but the website still has the same issue from before, pulling data from the old DatabaseInitializer, or at least somewhere other than my database.
I think we'll need to see code to troubleshoot further. We'd need to see your controller method all the way down to data access. One more idea: can you log back into your SCM site and check your App_Data folder and see if anything is there?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.