0

I'm trying to connect Microsoft Azure's Database using my ASP.NET but my connection string throws a Null Reference Exception during runtime. The Connection String is correct (I got it off MSDN and added my account details to it). Here's the connection string in the Web.config file:

<configuration>
<appSettings>
    <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=MYACCOUNTNAME;AccountKey=MYACCOUNTKEY" />
  </appSettings>
</configuration>

And I'm accessing the Connection string from the Code through this:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

The above code throws a Null Reference, pointing at the Connection String. What do you think is wrong? :)

MWUser
  • 267
  • 1
  • 7
  • 18
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Peter Duniho Feb 22 '15 at 06:50
  • That thread doesnt even state my question at all! It just states whata Null pointer is! I wana know if my Web.config file is correct dude @PeterDuniho – MWUser Feb 22 '15 at 06:52
  • Doesn't even relate to setting Azure Connection Strings -_- @PeterDuniho Now someones gonna mark it as 'answered' because of that tag. sigh – MWUser Feb 22 '15 at 06:53
  • Actually, that question also includes information on how to diagnose and fix a `NullReferenceException`, which is exactly the help you need here. Read the answer to that question, follow the recommendations, and if you still cannot solve the problem, edit your question so that it is more specific than "why do I get `NullReferenceException`?" – Peter Duniho Feb 22 '15 at 06:55
  • Riiiiiiiiiight. That dude below pointed directly at the problem. Thanks anyway :P lol @PeterDuniho – MWUser Feb 22 '15 at 07:00
  • Yup...just because a question is a duplicate of another one, that doesn't mean it _can't_ be answered. Only that it _shouldn't_ be answered. And of course, opinions vary. What can I say? You got lucky. – Peter Duniho Feb 22 '15 at 07:01

1 Answers1

2

You are using appSettings instead of connection strings. You need to change code to use appSettings:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
dotnetom
  • 24,551
  • 9
  • 51
  • 54