1

Well I was developing an ASP.NET webforms app in Visual Studio and it worked well. It has 2 SQL Server connection strings, one for ASP.NET Identity and the other for my own tables. Then I wanted to test my app on a real server. So I changed the connection strings to this:

<add name="DefaultConnection" 
     connectionString="Data Source=WIN-9I87AF3QUO9;Initial Catalog=aspnet-AdManager-20141230074246;Integrated Security=True"
     providerName="System.Data.SqlClient" />
<add name="StracturesConnection" 
     connectionString="Data Source=WIN-9I87AF3QUO9;Initial Catalog=aspnet-AdManager-20141230074246;Integrated Security=True"
     providerName="System.Data.SqlClient" />

Now the DefaultConnection works well. but the second one doesn't.

I get an error:

A network-realated or instance-specific error

here is the code of my DbContext

public class StructureDbContext : DbContext
{
    public StructureDbContext()
        : base("StructuresConnection")
    {

    }

    public DbSet<Structure> Structures { get; set; }

    public DbSet<StructureType> StructureTypes { get; set; }

    public DbSet<Reservation> Reservations { get; set; }
}

and this one is the db initializer:

    public class DatabaseInitializer : DropCreateDatabaseIfModelChanges<StructureDbContext>
{
    protected override void Seed(StructureDbContext context)
    {

        Structure s = new Structure();
        s.StructureTypeID = null;
        s.Description = "Test";
        s.CityID = 45;
        s.Address = "test";
        s.Price = 400;
        context.Structures.Add(s);

        StructureType t = new StructureType();
        t.Name = "بیلبورد";
        context.StructureTypes.Add(t);
    }
}

}

16
  • 1
    If they are identical connection strings, then it is most likely your code calling the second connection string isn't referencing correctly. Can you share some code showing how the connection strings are used? Commented Jan 31, 2015 at 10:38
  • well I don't have the code right now. but I use entity framework code first and these connection strings are in web.config file. Commented Jan 31, 2015 at 10:46
  • One is called StracturesConnection. Did you call it StructuresConnection in your code? (first a -> u) Commented Jan 31, 2015 at 10:55
  • yes. as I said it works properly on localdb. the name of the connections are the same as when I was developing on visual studio. Commented Jan 31, 2015 at 11:01
  • How do you know the first one is working? Integrated Security usually does not work out of the box on a server. Commented Jan 31, 2015 at 11:15

1 Answer 1

1

Well the problem is a miss spelling. in the connection string I wrote "Stractures" and this is wrong! sorry for wasting your time. I should go and check why this works on visual studio!

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

Comments

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.