0

The page in my application where database access is performed, I am getting an error which says

CREATE DATABASE permission denied in database 'master'.

Following is the url : http://price-tag.org/Store/Section/Computers.

I have created the database on hosting provider database server and following is my connectionstring

<add name="PriceCompareEntity" connectionString="Data 
   Source=rdinvent.db.8750445.hostedresource.com; Initial Catalog=rdinvent; User  
   ID=myDatabase; Password=myPassword;" providerName="System.Data.SqlClient" />

What can be the reason for this error? Also, why is it trying to recreate the database when I have already done that and there is no initialization for new database defined in Global.asax

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Pankaj Upadhyay
  • 12,966
  • 24
  • 73
  • 104

1 Answers1

3

Im assuming you are using EF CodeFirst? The reason this is happening is because you havent correctly passed the connection string settings into the CodeFirst Context object. This means its trying to create the ContextDB using the full name/namespace of the context.

undefined
  • 33,537
  • 22
  • 129
  • 198
  • yes i am using EF CodeFirst. I created a database on the hosting provider database server with the name rdinvent. – Pankaj Upadhyay Dec 25 '11 at 10:25
  • i am unable to understand what you mean. You mean to say that my above connectionstring defined in the web.config is the reason for all this. – Pankaj Upadhyay Dec 25 '11 at 10:30
  • You actually need to tell the EF provider which connection string from you web.config to use. By default it wont just pick the first one. In the place where you are instantiating the connection (global.ascx or wherever else) specify the connection string name. Refer to http://stackoverflow.com/questions/4805094/pass-connection-string-to-code-first-dbcontext for details on a similar situation – undefined Dec 25 '11 at 10:51
  • Everything has been working on development PC. I never need to explicitly define a connectionstring in gloabal.asax or anywhere else. I have used the same PriceCompareEntity class to work with SQL Express database and SQL CE – Pankaj Upadhyay Dec 25 '11 at 11:03
  • EF will automatically try and create a database based on your codefirst schema if it cant find one. It will automatically try and connect to a local SQLExpress or CE instance (which you probably have create rights on) and completely bypass the connection string. You will find that databases inside SQLExpress will match the namespace/name of your context. – undefined Dec 25 '11 at 11:14