I am working on my 1st mvc razor project. I set the project and on the 1st run I am getting an error that the _appstart.cshtml page can't connect to the database.
I can see the db in the app_data folder and on this line of code I am getting error:
WebSecurity.InitializeDatabaseConnection("StarterSite", "UserProfile", "UserId", "Email", true);
This is my 1st time working on mvc razor project, and every advice is welcome about what should I enter there.
UPDATE:
conn string in web.config:
<connectionStrings>
<add name="StarterSite" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\StarterSite.mdf;User instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
Make sure your connection string is pointing to the correct location (database). You can find it in your Web.config file in your solution.
e.g.
<connectionStrings>
<add name="WebContext" connectionString="Data Source=server.local;Initial Catalog=blops.test;Persist Security Info=True;User ID=Userid;Password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
Related
I'm currently completing an ASP.NET web app assignment which requires a n-tier design. On the marking guide for database design and implementation 1 mark goes towards:
"A DB login created to use for the Web Application connection String"
I've contacted my lecturer but no response about what I want to ask.
I have to hand in the SQL script as a script file. I'm wondering how do I create a DB login in the script? Or what does this mean when you read it.
Or am I over thinking this as I've already created a connection string and I've placed it in the web.config file which looks like this
<connectionStrings>
<add name="ConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DB; Id=myUsername;password=myPassword;Trusted_Connection=False; Integrated Security=True; MultipleActiveResultSets=True" />
</connectionStrings>
<connectionStrings>
<add name="DBConnection" connectionString="server=192.168.1.21\DBServer;database=DataBase1;user id=sa;pwd=wins123;Pooling=True;Max Pool Size=1000;Connection Timeout=2000;"/>
<add name="DBConnection1" connectionString="server=192.168.1.21\DBServer;database=DataBase2;user id=sa;pwd=wins123;Pooling=True;Max Pool Size=1000;Connection Timeout=2000;"/>
</connectionStrings>
server=192.168.1.21\DBServer Instead of this you can put Your SQL Server Name
Hi I am not able to connect I get an error server was not found, the problem is my connection string in the data source property in web config.
<connectionStrings>
<add name="dbHolaStaffConnectionString" connectionString="Data Source=localhost\SQL2016;Initial Catalog=dbHolaStaff;user id=xx;password=xx;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
I have chnaged the source in many ways but cant get it work.
DESKTOP-VNAJJMF\SQL2016
.\SQL2016
localhost\SQL2016
The server name in sql management studio is: DESKTOP-VNAJJMF\SQL2016
My user id and passwords are correct, how can I fix this problem? I dont know why visual studios keeps showing that error.
I also have enabled Remote access in sql server but nothing works.
Can you try with the below one
<connectionStrings>
<add name="dbHolaStaffConnectionString" connectionString="Server=DESKTOP-VNAJJMF\SQL2016;Database=dbHolaStaff;user id=xx;password=xx;MultipleActiveResultSets=True;Trusted_Connection=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
When publish a MVC website via Visual Studio it rewrites the connection string for Entity Frameworks with an invalid one.
It appears to be the same invalid one it created when I first imported the database model (not code first) The correct connection string is in my local web.config, and there are no changes being made by the web.release.config file.
Correct connection string:
<add name="Entities" connectionString="metadata=res://*/Models.MODModels.csdl|res://*/Models.MODModels.ssdl|res://*/Models.MODModels.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=R4S-MOD;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Generated connection String:
<add name="Entities" connectionString="Data Source=localhost;Initial Catalog=R4S-MOD;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.EntityClient" />
When you do a release publish they should show you a popup where you choose if you want to do filesystem or iis deployment. there is a section in the wizard which has connection string. check it there, if there is already a preselected value for your connection string – qamar
When I want to access to ASP.NET Configuration Tool it gives me the following error message:
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database.
What can I do. Is there any configuration which I should set before I can access or ?
I am using ASP.Net MVC4 Project with build in connection string.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AccountPortal-20131128183241;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AccountPortal-20131128183241.mdf" providerName="System.Data.SqlClient" />
you should access your connection string from web.config file before proceeding further.
web.config file :
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AccountPortal-20131128183241;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AccountPortal-20131128183241.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
from code : access connection string which is in web.config file
string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
i have developed a project. i am uploading this project in a server. i could not connect this with the database.
what will be thw path in web.config file. help me please.this is my connection string in web.config file.
<connectionStrings>
<add name="bcharyaConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"/>
</connectionStrings>
should i use database path there?
D:\microsoft sql server\data\bcharya.mdf
this path or
D:\microsoft sql server\data\bcharya_log.LDF
MDF Location
Put your .MDF file in App_data folder.
Connection string
<connectionStrings>
<add name="bcharyaConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\bcharya.mdf;
Integrated Security=True;
User Id=myUsername;
Password=myPassword;
User Instance=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Add a backslash "\" just after |DataDirectory| in your connection string:
AttachDBFilename=|DataDirectory|\bcharya.mdf;
<connectionStrings>
<add name="bcharyaConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\bcharya.mdf;User Instance=true"/>
</connectionStrings>
|DataDirectory| ( Enclosed in pipe symbols ) is a substitution string that indicates the path to the database.
To set the DataDirectory property, call the AppDomain.SetData method. If you do not set the DataDirectory property, the following default rules will be applied to access the database folder:
1: For applications that are put in a folder on the user's computer, the database folder uses the application folder.
2: For web application the database folder uses App_Data folder.
You can set the path in Application_Start method in your Global.ascx.cs
AppDomain.CurrentDomain.SetData("DataDirectory", #"D:\microsoft sql server\data");
DO NOT Forget to change
AttachDBFilename=|DataDirectory|\aspnetdb.mdf;
to
AttachDBFilename=|DataDirectory|\bcharya.mdf;
If the database is already attached to sql server change the connection to:
<connectionStrings>
<add name="bcharyaConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog = bcharya;User Instance=true"/>
</connectionStrings>
This way you don't need to set the |DataDirectory| path.