SQL Server database is readonly error - c#

I am trying to upgrade one of our web application from Windows Server 2003 to a new box with Windows Server 2012. The application allows us to create multiple instances of another application as virtual directories within a website. Its more like we create an instance of a web application on run time for every signup which is customer specific. Each instance consist of SQL server MDF file that it attaches to SQL server.
The problem I am having is that MDF file is from SQL 2008 and system fails to upgrade it to 2012. If I upgrade it manually then system complains that database is in readonly mode. I have already set application pool identity to Network Service account and I believe it should have sufficient rights to attach/read/write the database. I am unable to reproduce the problem on local system where I am using Windows 8 and SQL 2012. Any help would be appreciated.
Failed to update database "some.MDF" because the database is read-only.

Network service has not part in readonly database configuration.It could depend from login role.Have you check via ssms if login user has been bind to the database and if its has the right permission.
Take a look to the image below:
if not you need to setup right configuration for your customer and so on.

The only way to get it working was by allow Network Service full control permissions using NTFS folder permission dialog.

Related

Publish Web Page on Local Server

I have a Web App developed in Visual Studio Community 2019 utilizing ASP.NET, C# and HTML. I am trying to Publish the App locally so that it can be accessed by other Computer systems within the same server. I can successfully publish the static data (images, boxes, headings, titles, etc.) but the DataGrid on my web page does not displays any data.
I connected the data via connectionString to SSMS which works perfectly via IIS Express, if I run the application by opening Visual Studio. I am looking for a way where I don't require to open and Run the application and all computers within the same server can access it directly.
You can try using SQL Server (User name/password) authentication in connection string instead of Windows Authentication if not already done.
Also you can add the 'IIS APPPOOL\DefaultAppPool' user as a database user in your SQL instance, then providing the proper 'User Mappings' to the databases you need the DefaultAppPool user to access.

How to configure exe setup with database on another pc...?

I created my first winform application using c# windows form application in visual studio 2015. It contains some database operations such as insertion, deletion, and updates. The database is created in SQL-Server. Then I compiled the solution and it worked fine on my computer. When I try to run the application on another computer, it is throwing an SQL-Server connection error. Can you please help out, I am new to this.
When You run the EXE file on some other computer you should make sure that that computer is able to connect to your database server, So you should either Add the computer to your network and provide necessary rights to connect, or Host the database on Some Network Location from where everyone can access it.
Another Idea is if you want to keep the Database as Local for each Computer, try using the Dynamic Configuration using the App.Config File.Save and retrieve the Database Connection String from the App.Config File and when you copy the EXE to some other machine, Copy this file along with that.
The issue here seems to be on the client side. The user on the client/machine that runs the application on, doesn't seem to have the rights to connect to the server or database. You need to grant the needed rights to each user that will use the client.
However this concept allows the users to also directly connect to the database and run CRUD operations if they know how and are allowed to.
A more common way is to use a dedicated service user/account and include the credentials to the connection string in your application. Here are the basics.
If you need to make sure users don't read the credentials from the config file, use encrypted configuration
I think you are trying to permanently attach a database file (.mdf), which can be done by following steps: from the Data Connections node
Open the shortcut menu for Data Connections and choose Add New Connection.
The Add Connection dialog box appears.
Choose the Change button.
The Change Data Source dialog box appears.
Select Microsoft SQL Server and choose the OK button.
The Add Connection dialog box reappears, with Microsoft SQL Server (SqlClient) displayed in the Data source text box.
In the Server Name box, type or browse to the path to the local instance of SQL Server. You can type the following:
"." for the default instance on your computer.
"(LocalDB)\v11.0" for the default instance of SQL Server Express LocalDB.
".\SQLEXPRESS" for the default instance of SQL Server Express.
For information about SQL Server Express LocalDB and SQL Server Express, see Local Data Overview.
Select either Use Windows Authentication or Use SQL Server Authentication.
Choose Attach a database file, Browse, and open an existing .mdf file.
Choose the OK button.
The new database appears in Server Explorer. It will remain connected to SQL Server until you explicitly detach it.

cannot access sql server after publishing site in iis7

I am created a website using visual studio 2010. On the time of the development of website I am able to access the database.. but after publishing the site using IIS7..i was unable to access the database..the exception occured during that time was "the connection is in the closed state".in IIS7 When I changed the application pool identity to localsystem, it worked.
Data base is installed in the same machine. and server is SQL SERVER 2008 R2
you can only access database with sql authentication after publishing it.
In IIS7 the application pool by default runs under the IIS AppPool\[Application Pool Name]
That means, if your app pool is called "MyWebSite", then you must give the following user permissions to use your database: IIS AppPool\MyWebSite
It won't be in any list, so you'll have to type it as above when adding it.
I suggest making it database owner if you're in doubt about which permissions to give it. If it works, you can always refine the permissions later

Connection String in C# windows application

I am developing C# windows application first time.
Que 1 - ) I have developed my windows application which uses SQL server 2008 using below connection string..
Data Source=myMachineName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
But When I created setup of my application and installed it to another computer then it is throwing error of could not establish connection with SQL server..
I guess this error is because of my connection string as it is specific to my computer and installing it to another computer will not work..
Hence How can I make my connection string which will work with any computer..
Que 2 - Do I need to attach schema file with my setup as How my database will be created into the other computers??
This might be silly qustion but as I am doing this first time , i dont know about this all.
Regards,
Mahesh
You should place your web config in app.config file which is in xml format.
And read it from your code.You can easily change app.config file through notepad according to machine.
Yes must have your schema script in setup if you want to create it from setup.Otherwise you create database manual on client machine.
If you've used SQL Server on your development machine, it has to be installed on every computer that will be using your app. There are several options to resolve this issue:
If your app doesn't need access to a central sql server (for example your app just keeps track of users DVDs), use SQL Server Compact Edition instead and embed it to your app
If your app needs some kind of a centralized data, get a dedicated SQL server first, install there everything you need and in your app change your current myServerAddress to the address of the server. Note that the server needs to be accessible from remote locations (some restrict access to localhost!).
Que 2 - Do I need to attach schema file with my setup as How my
database will be created into the other computers??
Again, multiple options. For instance, you can export your database to a .sql file (Right click on the db in your DB explorer and select option Publish to provider) and then import it using a sql manager on other computers. Or maybe you can create a .cs installation script, that will do the same job using C# code.
Edit based on OP's comments:
Example links for solutions:
question1: Embedding SQLServer CE in an installer
question2: http://support.microsoft.com/kb/307283
Okay that's fine but will my current Connection string work in that case as the DataSource
is my specific machine name
Of course not, you'd have to change it to point to the SQL Server CE database file. Probably the best way is to not hardcode it, but use a relative path to the database. It looks like this for instance:
Data Source=|DataDirectory|\MyDb.sdf, where |DataDirectory| points to the App_Data folder of your application.
Also plese see the error screen map i have attach with the question..
Your error is quite clear - there was a problem establishing a connection to your database. It either doesn't exist or isn't accessible from your current machine.

LINQ to SQL works only in debug mode?

This is my code :
DataClassesDataContext data = new DataClassesDataContext();
var hey = from p in data.Provas
select p;
Response.Write(hey.First().title_it);
if I open this playing start to Visual Studio, it opens http://localhost:51180/Website1/ and I get the value taken from DB.
But, if I open the website with http://localhost:8080/ (which usually I open with this) I get :
System.Data.SqlClient.SqlException: Cannot open database "Website1" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\Website1'.
How can I should settings? IIS problem?
As #usr pointed out the answer is in front of you.
When you run the app in debug mode form Visual Studio the user connecting to the database is the user logged into the PC and running Visual Studio - the odd are that this user (you!) is an administrator and has administrator rights with SQL Server (I'm assuming a local instance).
When you run the app via the local installation of IIS (which it is reasonable to assume is the full version, not express) then, unless you change the app pool for the application, it will be running as a local system user (right now I forget which one, you can go look at the app pool to see) and by default that user will not have access to the databases in SQL Server.
To fix this you need to do one of two things either:
a) Change the user in the app pool to one that has rights to the database in SQL Server (if you want good practice then you should define an explicit user)
b) Grant the appropriate rights to the appropriate system account to access the database
(Note that in both cases you're going to need to add the user to SQL Server using Management Studio or equivalent)
Verify login names on http://localhost:8080/. Possibly this article will help you.

Categories

Resources