none
System.Data.Entity.DataBase.Exists(connextionstring) returns FALSE RRS feed

  • Question

  • Hello, I am using the Universal ASP.NET Membership provider; The user data and my own data are stored in the same database sharing the same connection string. its works perfectly on my local development environment. I have transfered  the site to the remote host "1and1, copied the database (schema + content) with a SQL statement AND I get now the following error when trying to log in : CREATE DATABASE permission denied in database 'master'.  Normally, ASP.NET should not create a database because I gave a valid connection string pointing to an existing database with the required tables (User, Membership, etc.). But it seems that ASP.NET does not see this DataBase and try to create a new one.

    I think the problem is coming from  Entity Framework.

    on my remote host (1 &1) :

    System.Data.Entity.Database.Exists("ConnectionString1"); // return FALSE !!
    <add name="ConnectionString1" connectionString="Data Source=dbXXX.db.1and1.com,1433;Initial Catalog=dbXXX;User Id=dboXXX; password=*****" providerName="System.Data.SqlClient"/>

    on my local host :

    System.Data.Entity.Database.Exists("LocalConnectionString1"); // return TRUE !!!
    <add name="LocalConnectionString1" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\XXX.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    On the the remote host, I can query my entity model and run sql statement based on connection string. So the connexion string is working. Any idea will be very welcomed : I have spent by two last days trying to find a solution.... Regards

    • Moved by CoolDadTx Wednesday, March 12, 2014 8:32 PM EF related
    Wednesday, March 12, 2014 5:43 PM

Answers

  • My problem was coming from '1and1.fr". I solved my problem simply by changing my hosting provider. I am now working with Microsoft Azure and everything is much more simple. Regards
    Sunday, March 16, 2014 9:36 AM

All replies

  • Hello,

    >>System.Data.Entity.Database.Exists("ConnectionString1"); // return FALSE !!

    If it returns false, it means that the application has connected to the server successfully, however it does not find the database in server according the database name in connection string. Please check whether the database name is correct.

    >>On the the remote host, I can query my entity model and run sql statement based on connection string.

    Do you mean that you can use the connection string to connect to remote sever at client side and do queries successfully?

    If not, you can have a try write a small ADO.NET project to check the connection string whether it can connect to the remote server.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 13, 2014 5:20 AM
    Moderator
  • Many thanks for your time. I can use the connection string to query the database in aspx.cs page on the remote host. For instance, the following script is working :

    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);
    string queryText = @"select * from Users";
    SqlCommand com = new SqlCommand(queryText, con);
    con.Open();
    System.Data.SqlClient.SqlDataReader reader = com.ExecuteReader();
    TestLabel.Text = reader.HasRows.ToString(); // Returns TRUE
    con.Close();

    The page I am testing is very simple :

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="_Default" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> 
        <br />  
        <asp:Label runat="server" ID="TestLabel" /> 
        <asp:LoginView ID="LoginView1" runat="server">
            <AnonymousTemplate>
                <asp:Login ID="Login1" runat="server" LoginButtonText="Connexion" PasswordLabelText="Password" RememberMeText="Remember Me" UserNameLabelText="Email address" DestinationPageUrl="~/Pages/Projects/EditProjects.aspx" PasswordRequiredErrorMessage="A password is required" UserNameRequiredErrorMessage="An Email is required" BorderStyle="None" FailureTextStyle-CssClass="ErrorMessage" LoginButtonType="Link" TextBoxStyle-BorderStyle="Solid" TextBoxStyle-BackColor="LightGray" BorderPadding="1" TextBoxStyle-BorderColor="White" TextBoxStyle-BorderWidth="2px" HyperLinkStyle-HorizontalAlign="Left" InstructionTextStyle-HorizontalAlign="Left" LabelStyle-HorizontalAlign="Left" TextBoxStyle-Width="300px" TextBoxStyle-Height="30px" TitleTextStyle-HorizontalAlign="Left" TitleText=" " FailureText="Login falied. Please retry.">
                </asp:Login>
                <!-- <asp:HyperLink runat="server" NavigateUrl="~/Pages/Account/SignUp.aspx" Text="Create an account" /> -->
             </AnonymousTemplate>
            <LoggedInTemplate>
                You are logged in<br />
                <asp:HyperLink runat="server" NavigateUrl="~/Default.aspx" Text="Go to home page" />
            </LoggedInTemplate>
        </asp:LoginView>
    
        </asp:Content>
    Any idea will be very welcomed !

    Thursday, March 13, 2014 12:07 PM
  • Is it that you are using Code First since it tries tocreate a new database? Since this approach has wrong, you can have a try to use the database first way.

    If I misundertsand, please let me know.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 14, 2014 10:06 AM
    Moderator
  • Is it that you are using Code First since it tries tocreate a new database? Since this approach has wrong, you can have a try to use the database first way.

    Many thanks. Very good suggestion  indeed. How can I try to use the database first way ? How can I know if I am using Code First ? I am puzzled because Database.exists("Connectionstring1") returns True on my local host, false on the remote host with no code change except a different connection string in my web.config. Grrrrrr....

    Regards

    Friday, March 14, 2014 10:58 AM
  • My problem was coming from '1and1.fr". I solved my problem simply by changing my hosting provider. I am now working with Microsoft Azure and everything is much more simple. Regards
    Sunday, March 16, 2014 9:36 AM