locked
Mvc Default Database RRS feed

  • Question

  • User1027872733 posted

    Hi Friends

    I am reading 

    https://www.c-sharpcorner.com/UploadFile/4b0136/getting-started-with-iis-host-and-publish-in-mvc-5/

    when i  built the same application 

    my framework is  4.5.1 

    it is not giving me default database 

    cool<add name="DefaultConnection"connectionString="Data Source (LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcIISDemo-20130911053147.mdf;Initial Catalog=aspnet-MvcIISDemo-20130911053147;Integrated Security=True"providerName="System.Data.SqlClient" />  

    also the link has the same framework 

    i use vs community 2017

    sql server 2014

    Thanks in advance

    Anil Srivastava

    Pune-India

    Tuesday, June 18, 2019 2:03 AM

Answers

  • User283571144 posted

    Hi Anil,

    As far as I know, the connection string is a string that specifies information about a data source and the means of connecting to it. You should make sure your connection string's address is right, then you could make your application work well.

    If you want to use sql server 2014 as your application's database, I suggest you could try to use below connection string format:

    Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;

    The server means the Host/IP Address of the sql server machine.

    The database means the sql server's database.

    The ID means the userid which is used to login in the sql server.

    The password means the user password which is used to login in the sql server.

    Besides, if you want to use the *.mdf file in the App_Data folder of an ASP.NET web application to connect to local SQL Server Express instance, I suggest you could try to use below connection string:

    Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;
    Trusted_Connection=Yes;

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 18, 2019 5:58 AM
  • User1027872733 posted

    PatricSc

    Likely not. You have some code that initialize ASP.NET Identity and that does use it ? Just having a connection string in the config file is not enough to create the db. It is created (if configured this way) when you try to actually use the DbContext that uses this connection string

    Thanks for this

    The link is great except it does not discuss DbContext

    I think Db is preconfigured  in some way

    I will do in-built providers as membership, roles

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 19, 2019 5:07 PM

All replies

  • User-1038772411 posted

    Hello Anil Srivastava,

    In your reference it is given as reference of their connection string(In step 4 it is written the connection property is available on my file). so it is not same for you. You have to replace your database source name there

     Config-in-MVC5.jpg

    The above image shows that you have to put your data source name here. 

    For your reference please refer the below code

    <connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=DESKTOP-9KJ13Q9\SQLEXPRESS;Initial Catalog=TestNew;Integrated Security=True" providerName="System.Data.SqlClient" />
    </connectionStrings>

    In the above code Data Source=DESKTOP-9KJ13Q9\SQLEXPRESS  is my sql server name and TestNew is my database. 

    I hope this will help you. 

    Thank you.

    Tuesday, June 18, 2019 5:38 AM
  • User283571144 posted

    Hi Anil,

    As far as I know, the connection string is a string that specifies information about a data source and the means of connecting to it. You should make sure your connection string's address is right, then you could make your application work well.

    If you want to use sql server 2014 as your application's database, I suggest you could try to use below connection string format:

    Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;

    The server means the Host/IP Address of the sql server machine.

    The database means the sql server's database.

    The ID means the userid which is used to login in the sql server.

    The password means the user password which is used to login in the sql server.

    Besides, if you want to use the *.mdf file in the App_Data folder of an ASP.NET web application to connect to local SQL Server Express instance, I suggest you could try to use below connection string:

    Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;
    Trusted_Connection=Yes;

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 18, 2019 5:58 AM
  • User1027872733 posted

    Ashish

    this is connection string

    <add name="DefaultConnection" connectionString=" Data Source =SWATI\SQLEXPRESS; Initial Catalog==MyFirstMvc;  Integrated Security=True"
    providerName="System.Data.SqlClient" />

    But it is not initialsing 

    Like

    Roles

    Userclaims

    UserLogin

    i know how to initialize database via web.config

    Tuesday, June 18, 2019 7:18 AM
  • User-1038772411 posted

    Hello Anil Srivastava,

    As per your above reply , you have make mistake for initializing connection string 

    <add name="DefaultConnection" connectionString="Data Source =SWATI\SQLEXPRESS; Initial Catalog==MyFirstMvc;  Integrated Security=True"
    providerName="System.Data.SqlClient" />

    You use double time equal to change it to Initial Catalog=MyFirstMvc

    Thank you

    Tuesday, June 18, 2019 12:02 PM
  • User1027872733 posted

    Hello Ashish

    I have tried on frameworks

    4.5

    4.5.1

    4.6

    4,6,1

    4.6.2

    but the database with following table

    Roles

    Userclaims

    UserLogin

    is not  there this is project structure

    Project Structure

    Update: 

    still the issue is not fixed

    the database is not there with roles and other stuff

    I think the problem is with the framework/ installation that i am using 

    Wednesday, June 19, 2019 5:23 AM
  • User753101303 posted

    I think the problem is with the framework/ installation that i am using 

    Likely not. You have some code that initialize ASP.NET Identity and that does use it ? Just having a connection string in the config file is not enough to create the db. It is created (if configured this way) when you try to actually use the DbContext that uses this connection string (AFAIK even creating the context is not enough, it is really created when there is no way around going further without creating the db ie doing a query for example).

    Wednesday, June 19, 2019 9:02 AM
  • User1027872733 posted

    PatricSc

    Likely not. You have some code that initialize ASP.NET Identity and that does use it ? Just having a connection string in the config file is not enough to create the db. It is created (if configured this way) when you try to actually use the DbContext that uses this connection string

    Thanks for this

    The link is great except it does not discuss DbContext

    I think Db is preconfigured  in some way

    I will do in-built providers as membership, roles

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 19, 2019 5:07 PM
  • User753101303 posted

    And so what happens when you are using the "Register" option (do you even have one ?)

    If not I believe he cropped a screen too much which doesn't show you should also change the "authentication option" to "individual user accounts". Do you have the "Register" option in your app ?

    Edit: just a quick confirmation that all works fine here. If the "Register" screen is missing make sure to use the "Individual User Accounts" option as shown at https://docs.microsoft.com/en-us/aspnet/visual-studio/overview/2013/creating-web-projects-in-visual-studio#authentication-methods

    Then the db should be created when using the "Register" form (and if it fails tell us which error happens)

    Wednesday, June 19, 2019 5:37 PM
  • User1027872733 posted

    If the "Register" screen is missing make sure to use the "Individual User Accounts" option as shown at https://docs.microsoft.com/en-us/aspnet/visual-studio/overview/2013/creating-web-projects-in-visual-studio#authentication-methods

    Thanks Community

    I got The complete idea of Identity

    I what way should I Thank You all the members of community 

    I also uploaded the MVc Project using identity

    https://github.com/Anil1111/LearnIdentity

    Once Again Thanks All

    Anil Srivastava - Pune(India) 

    Sunday, June 23, 2019 7:09 AM
  • User409696431 posted

    "I what way should I Thank You all the members of community "

    To thank those who helped you, mark the post or posts that led you to the solution as Answers to your question.  In addition to giving helpful people credit, this highlights that answer (or those answers) in the post thread so that others who have the same problem will see them.

    Sunday, June 23, 2019 11:05 AM