How can I interact with a .mdf or.ldf file? When I say interact, I mean view/edit fields, records on the desktop.
Its inside a websites App_Data folder.
These are SQL Server files. MDF is the data file and LDF is the log file.
Basically, I think your web site is using SQL Server for it's data storage, and the database is stored in that APP_DATA folder.
Usually SQL Server installations come with Management Studio or Enterprise Manager (called Client Tools) unless the administrator chose not to install it on that machine.
Look under START / Programs / Microsoft SQL Server 2000/2005/2008. Then look for Enterprise Manager or SQL Server Management Studio.
In the ServerName, just put a period or dot, and use Windows Authentication to connect. If that does not work, you will need a username and password to connect to the database. You should be able to find either in the configuration files of the web project, or the website code.
If the Tools are not installed, then you will need the installation CD / DVD to install the client tools.
Alternately, you can install Tools (only Tools, you don't need the database engine) from SQL Express Edition from http://www.microsoft.com/express/sql/default.aspx?wa=wsignin1.0 on a different machine and access the database from there.
To "interact" with an mdf file, you need to attach the database to an MS SQL Server.
After located the mdf file you can use follwing stored procedures:
sp_attach_db
ex:
EXEC sp_attach_db
#dbname = N'MyDatabase',
#filename1 = N'D:\DataFiles\MyDatabase_Data.mdf',
#filename2 = N'E:\LogFiles\MyDatabase_Log.ldf';
Wehn DB is attached you can connect with your connection string and do classical operations on database.
You can detach your DB with sp_detach_db
ex:
EXEC sp_detach_db
#dbname = N'MyDatabase';
MSDN sample : http://msdn.microsoft.com/fr-fr/library/ms179877.aspx
Use linq2sql to access the mdf.
There's an example in an answer here
Related
I've created an ASP.NET website which runs perfectly from Visual Studio. It connects to a SQL Server .mdf database file in the App_Data folder. I published the project using FTP. The live website cannot however connect to the database, as it is LocalDB, and my host uses a SQL Server (SqlException (0x80131904))
I uploaded an identical copy of the local .mdf database file from my computer to the host's SQL Server. I then tried to form a data connection with the server database from Visual Studio, however my host doesn't allow remote database access, for security reasons, resulting in error 40.
I'm using ASP.NET MVC in my application so I need access to the database to create models. My host has said "you can access SQL Server databases using ASP scripts running on your presence".
So my question is: how do I create models based on my host's SQL Server database when remote access isn't allowed?
When you're testing with Visual Studio, you should connect to the local copy of your database. When you're ready to publish your application, copy the database to the remote sql server and attach it. The copy of your application which is published should then connect to the uploaded database on that server.
That way you have one environment for testing and one for real use. There shouldn't be any need for Visual Studio to connect to the remote database.
P.S. To allow you to connect to different databases in different environments, usually you set your database connection string in the web.config file. So if you create different config transforms for each build configuration (e.g. debug and release) then visual studio will create the correct version of the config file when you do a Publish operation. See https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations for info about configuration transforms.
I have successfully deployed my asp.net web form application on appHarbor and also installed SQL Server.
But I don't know how to make database as I could not find any query box of shell where I can run my schema script.
A good way to do is to download the SQL Server express 2014 that will allow the connection with add-on that you install in https://www.microsoft.com/en-us/download/details.aspx?id=42299.
with the SQL management you can grab the Host Name as server name, then use sql authentication and put your username and password.
then you can manage all your database in your site, and in Visual Studio the only thing that you need to do is provide the connection string that appHarbor gave you and copy and paste to the web.release.config.
My requirement is to deploy an ASP.NET application in which I have a core library class project, service layer and a UI layer, using SQL Server database as backend.
My client needs to deploy it using some MSI or EXE, in which he / she should able to customize the installation to IIS and his SQL Server.
What I want to say, when I execute the EXE, it will ask me the basic requirement for the IIS like server name, virtual directory name, app pool etc , then automatically deploy it there. Now it should also ask the same for SQL Server database installation like server name, authentication, database name and so on....
I have tried but I can manage to deploy ASP.NET app not able to customize the SQL Server installation.
Also tell a feasible solution, as my database size is around 6GB. What will be optimized way to create a installer for that?
I once had to do something similar but my database was much smaller.
I scripted out my database into T-SQL statements for its creation from scratch and stored those in a text file.
I then wrote a .NET windows app that would prompt the user for SQL Server network location and credential information. This .NET application had the database creation SQL text file included in the executable as a resource file, and would connect to the specified SQL Server and execute the commands in the text file one by one. I was able to read the text file and parse commands out by delimiting on the keyword "GO"(linebreak).
I am trying to deploy my web application created with asp.net in visual studio 2010. I have successfully created .exe and .msi file, install it and run using IIS Manager. However, it needs a database which is why it is returning
System.Data.SqlClient.SqlException: The SELECT permission was denied on the object 'TableName', database 'master', schema 'dbo'.
whenerver I try to run it on browser with localhost.
How do I include my database file in deployment so that when I install my application in another computer, the database will also be created?
It is not at all clear what exactly you mean by database file but if you are referring to an SQLLite or SQL Server CE database file all you have to do is go to properties and change the "Copy to Output Directory" property to "Copy if Newer" (don't forget to do the same with the required class libraries).
If you are referring to SQL Server, Oracle or some other RDBMS database than you can't just copy the file, you'd have to either use DDL to create the database or attach the database file using the SSMS.
EDIT: I did not pay attention to the exception you posted so the second part of my question is relevant. SQL Server database file cannot be just copied to another computer, the target computer must have the SQL Server installed and you must detach the file from your local SQL Server and attach it on the remote SQL Server using the SQL Server Management Studio.
I have an ASP.NET project that also uses a SQL MDF File. My target server is SQL 2008R2 or SQL Azure.
I would like to know what deployment options I have as I migrate from DEV to PROD. In case it matters I'm not under any regulation to maintain PII or similarly private data.
How do I move my test schema and perhaps data to production?
You can move the entire database, including the data by attaching the MDF file to the new SQL server. Otherwise you can select all objects and generate CREATE scripts to copy the schema over.
Yes, you can attach to the MDF file directly, or do a backup / restore to get it over to SQL Server 2008.
I haven't played with SQL Azure... From what little I've heard I think you might be stuck scripting the data as durilai suggested (last I heard we're not allowed to do backups / restores for SQL Azure).
In SQL Server Management tools, right click on the database and click 'Script Database As' to create an SQL script for your database. You can also do something similar at the table level if you want the data.