I am trying to deploy a MVC Application on the IIS server.
I have shared the sqllocaldb using command prompt and created a Private LocalDB instance with name IIS_DB
I have also changed the connection string in my Web.Config file to
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\.\IIS_DB;Initial Catalog=aspnet-MvcApplication26-20141226150050;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication26-20141226150050.mdf" providerName="System.Data.SqlClient" />
As of now I can view the Home Page when I click on Browse from the ISS Manager.
But when I click on the Register/Login hyperlink, I get the following error
Cannot attach the file 'C:\inetpub\wwwroot\MvcApplication26\App_Data\aspnet-MvcApplication26-20141226150050.mdf' as database 'aspnet-MvcApplication26-20141226150050'.
I finally solved this by manually copying the APP_Data folder from Visual Studio to the my application directory on the IIS server
After sharing the database here is what you have to do
Go to visual studio => databaseexplorer => add connection
For the server name enter (LocalDb).\IIS_DB then right click on the connection and choose new query and execute this command:
create login [IIS APPPool\DefaultAPPPool] from windows;
exec sp_addsrvrolemember N'IIS APPPool\DefaultAPPPool, sysadmin
Related
I am deploying my ASP.NET application on IIS. Everything works well when I run it on Visual Studio with IIS Express but when I use IIS, the event viewer shows this error.
I added a login on SQL Server but still get the same error
Any idea on what I could be missing?
Grand DB_Owner permission for "IIS APPPOOL\test.bata.com". also check the connection string in web.config file
You can try to use custom identity in application pool with the windows user name password and use this string in web.config file.
<add name="umbracoDbDSN" connectionString="data source=YOUR_SERVER_NAME;database=nrc;Integrated Security=SSPI;persist security info=True;" providerName="System.Data.SqlClient" />
For more detailed steps you can refer to this link: https://forums.iis.net/t/1249665.aspx
I need help solving this problem. I created the application installer using MS Visual Studio Installer Projects and ran it on another device. There were no versions of LocalDB that installed on my computer (2016 and 2017) in the prerequisites, so I had to download the SQL Server 2017 LocalDB on another computer manually. After that, when I started the program I received the following error.
Database files were automatically placed during installation in the folder Documents
I changed the connection string as follows:
string dbPathMyDoc = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string dbPath = Path.Combine(dbPathMyDoc, "myprojectAppData");
AppDomain.CurrentDomain.SetData("DataDirectory", dbPath);
Database path
So it seems to me that the problem is not the connection string, but then what?
I found that I can not check the version of SQL Server LocalDB installed on a second computer through the Command Prompt using the command sqllocaldb info MSSQLLocalDB (because of an error).
So I decided to recreate the MSSQLLocalDB instance using the following commands:
1) sqllocaldb d MSSQLLocalDB
2) sqllocaldb c MSSQLLocalDB
And after that the program successfully connected to the database.
I hope this information helps someone.
I make sample fixed problem for all project when create ny winforms & localdb
You can create 2 ConnectionString in App.config file
App.config
<add name="DevConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" /> <!-- *1* Use when publish project-->
<!--<add name="AppConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='E:\My Projects\MyDatabase.mdf';Integrated Security=True"
providerName="System.Data.SqlClient" />-->
<!--*2* Use for development-->
First use when you want develop system Developer Environment
Second CS use when app publish Publish Environment
For second connection-string must write full path
Code
For get connection String in App.config file, you can use this code
var conStr = ConfigurationManager.ConnectionStrings["DevConnectionString"].ConnectionString;
Initially I developed my project by putting the .db file within the project folder. Now I want to host the database on localhost so I put the db file on a new folder and started a http-server using node.js on localhost:8080. To start the server I used this command on node.js command line C:\Users\Me\aswserver>http-server .
aswserver folder contains only aswDB.db.
On my C# project until now I used the connection string
<connectionStrings> <addname="SQLite"connectionString="DataSource=.\aswDB.db;Version=3;"providerName="System.Data.SQLClient"/>
</connectionStrings>
and included the db file to project(Build Action: Content and Copy to output if newer).
After hosting the db on localhost I tried this connection string
<connectionStrings>
<add name="SQLite" connectionString="Data Source=localhost:8080/aswDB.db;Version=3;" providerName="System.Data.SQLClient" />
</connectionStrings>
Now when I try to connect to the db from the project I get Exception saying "The given path's format is not supported". How do I set up the connection so that any change I make to the db stays in aswDB.db on the server? (I plan to connect it to a Xamarin.android app too)
I have a project and want to publish it to azure . I tried to publish it but I have no idea.
I have no problem with publishing my project, but how I can upload or publish my sql database that I created using entity framework code first migration with my project, because I have data on it also the tables , so anyone have Idea of instructions how I can publish my project with the sql database?
Update: I Published my project , after I created a db and web app on azure but I have a problem with editing my connection string , if someone can help with that ..
My deafault connection string :
<add name="SmartBookLibraryModel1" connectionString="data source=FIRAS-JC\SQLEXPRESS;initial catalog=SBL;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" />
and this connection string I got from the sql database from azure :
Server=tcp:jhm8n1ya03.database.windows.net,1433;Database=smtebooAIkF3XGJh;User ID=Firasmsw#jhm8n1ya03;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
how the new one should be look ??
Thanks.
Basically you have to create the azure database. Add the connection string to your configuration files (web.config). Make sure the user you use in the connection string has the rights to do the changes to the database. And then deploy the project to azure.
When the application starts, the migrations will be applied to the database.
get started migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application
I am using a db from (localdb)\V11.0 server and able to connect successfully when using IIS express from VS2013, but when deployed in LocalIIS, it gives me an error below -
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible.
In order to fix that I have updated applicationHost.config file as below
<add name="DefaultAppPool">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
Now, though database is not connected, it has displayed a home page, but all data-driven dropdown values are empty. I have also tried changing Application pool to LocalSystem but website unable connect db. Is there any specific area that I need to investigate?
To get local db running with IIS on my machine, I followed the guidance in this msdn blog
The solution that worked best for me was to configure IIS application pools to run as my windows user.
This is done via the IIS interface. In the "Application Pools" section, right click on one (or more) and choose "Advanced Settings". Choose "Identity" and "Custom" then enter your username and password.
You can check if Application Pool / Local System has an account to access the database. There is also an option to user impersonate user https://support.microsoft.com/en-us/kb/306158
example:
<identity impersonate="true" userName="accountname" password="password" />