When building an ASP.NET MVC Web Application on Visual Studio 2017 I select the option for individual user accounts for built-in register and login functionality. This tells me that it uses a SQL server database for user profiles. After registering a user I am struggling to find this database and the data in visual studio, I cannot find the SQL server database it was referring to when creating the project. Does anyone know where this database is stored as I need to use it for other functionality.
Take a look at the connection string (look in appsettings.json for a Core app, otherwise web.config)
you might see something like this: "Server=(localdb)\mssqllocaldb;Database=...."
To access this in SQL Server Management Studio, just enter (localdb)\mssqllocaldb as the server name and connect with Windows Authentication, then the Database referenced in the connection string will be accessible.
If you want to access this directly from Visual Studio, select View -> Server Explorer. Once this window is open, Select Connect to a Database. For the Data Source, select Microsoft SQL Server (SqlClient) and for Server Name Enter (localdb)\mssqllocaldb, now the database referenced in your connection string should be able to be selected under the Connect to a Database section.
It's worth noting the database may not be available if you have not run the initial migration.
This db is created at runtime... you will not see it after creating your project, you must run it at least once, add a user, and then the Entity framework will create the db structure.
Related
I published my site on a web server and it works very well (at least to access it) but I would like to use the DB that was automatically created when I was in a development environment.
I initially checked 'Individual account' by creating the project, made some changes (creation of roles, fields in the ASPnetUser table, etc), did some stuff and then publish it and now I would like to recover the DB i had when i was working with Visual Studio on this app (the data inside does not matter to me).
When I published my site with Visual Studio 2017, I was asked to check the providerName and the context.
So I ticked both options leaving the basic information (System.data.SqlClient & connection string to my context (who's not the basic ApplicationDbContext)).
Then, browsing my site, I tried to connect to a login that existed in development on my machine but no way, I also tried to create a new account (thinking that this would regenerate a db) but no way either.
I looked on the internet but I found nothing, except for Microsoft but they use Azure, which does not interest me.
Could you guide me on the processes to follow (even just a link to a tutorial would be very useful)?
I still specify that the server is on Windows Server 16
The best solution for this, in my opinion, is to install a standalone MS SQL server on your machine and create the base of your project not on localdb, but on that server (you need just to change connection string in your Web.config to do it).
Can't access Northwind database from Visual Studio
I am working on my own computer, and created tne Northwind database from a script file. i should be the admin on the computer
and can access the table from SQL Server
From windows explorer, I right click the table and I can see two accounts that have full control (full control, modify, read etc are all checked). those accounts are
SQLServerMSSQLUser$Gary-PC$Gary (Gary-PC\SQLServer..
Administrators (Gary-PC\Administrators).
However, when i select the table to try to connect to it in VS, i get the message, you do not have permissions to view this file.
is there something else I have to do in SQL server to set permissions? or might it have something to do with the user context not being one of these two users in visual studio?
I guess you mean the Server Explorer/Database Explorer in Visual Studio, When you add a connection in Server Explorer there is a field for user name and password, however the default is using Windows Authentication, if you don't use that you probably have to set your user id correctly there.
Server Explorer/Database Explorer can be access from the View menu, for the existing connection you need choose the modify menu.
Please note if you connect from your code, the connection string is set in your code .NET, C# or configuration not from the server explorer, you need to set them separatly.
I don't have the exact the same version of C# Express installed, the settings might vary a little on different versions.
The connection string in Database Explorer/Server Explorer is depending on the the data source you use. You might want to look at this to connect to SQL Server using Microsoft SQL Server(SqlClient)
Then you can see the SQL Server Authentication method from Visual Studio Express.
You may also need to change the SQL Server Authentication, That is in SQL Server Management Studio Object Explorer, right-click the server, and then click Properties. On the Security page, You can see Server authentication, MSDN has that well documented.
I am trying to learn C# and then I hit this roadblock. My Visual Studio 2010 wont let me create a service based database (the .mdf file). (Add>New Item>Service-Based Database)
Everytime I try to add new .mdf it would bring up an error.
A network-related or instance-specific error occurred while
establishing a connection to the SQL server. The server was not found
or was not accessible. Verify that the instance name is correct and
that SQL Server is configured to allow remote connections. (provider:
SQL Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
I can create a Local Database (Add>New Item>Local Database) without any problem, but I cant create .mdf
I am running on Windows 7 64bit OS and Visual Studio 2010 (Ultimate).
A service-based database needs to connect to a SQL Server instance. It's not built into Visual Studio, it's a separate application which needs to be running somewhere for you to connect to. That error message is basically telling you it can't find the SQL Server instance you're trying to connect to.
Local Database works correctly because it keeps everything local to your application and doesn't require an external database server to function.
Basic requirements for using these two kinds of databases:
Local Database (.sdf): requires SQL Server Compact. That is, you need only an additional DLL, but no special system service. (If you know SQLite: SQL Server Compact is conceptually the same thing, only more powerful and feature-complete.)
Service-Based Database (.mdf & .ldf log/journal file): requires a running instance of SQL Server or SQL Server Express, both of which are standalone products (as Tim Copenhaver points out in his answer). For development purposes, you'd typically install one of these products on your development machine.
Likely cause of your problem: Guessing from the error message that you posted, you do not have SQL Server, nor SQL Server Express, installed. However, an instance of one of these products is required so that you can "attach" your database to it. This is required in order before you can actually access the .mdf database.
To see whether you have SQL Server installed, you could e.g. open Control Panel → Administrative Tools → Services, and look out for a system service named "SQL Server (.\SQLEXPRESS)", or "SQL Server (YOURCOMPUTERNAME\MSSQLSERVER)", or similar. The name in the brackets is the name of the database instance running on your machine. SQLEXPRESS is the default instance name for SQL Server Express, while MSSQLSERVER is the default instance name for the full version of SQL Server.
If you do not have SQL Server installed, you can download e.g. SQL Server 2012 Express or SQL Server 2008 R2 Express with SP2 for free from Microsoft.
You can try
Go to Command Prompt from Start->Run(type cmd -> press enter)
Check SqlLocalDB by
Sqllocaldb.exe i
You will see version number like (v11.0) otherwise complete the
installation.
Create the sqldb by
sqllocaldb c dbname
You will see like "LocalDB instance "dbname" created with version 11.0."
Then Start the Db
sqllocaldb s dbname
You will see like "LocalDB instance "dbname" started"
See the created Db info
sqllocaldb.exe i dbname
Now try to create service-based database in c#.
To temporarily attach a database file (.mdf) from the Data Connections node
In Server Explorer, open the short cut menu for Data Connections and choose Add Connection.
The Add Connection dialogue box appears.
Choose the Change button.
The Change Data Source dialogue box appears.
Select Microsoft SQL Server Database File and choose the OK button.
The Add Connection dialogue box reappears, with Microsoft SQL Server Database File (SqlClient) shown in the Data source text box.
Choose the Browse button and browse to an existing .mdf file.
If you type a file name that does not exist, a blank .mdf file will be created.
Select either Use Windows Authentication or Use SQL Server Authentication.
For more information on SQL Server database access authentication, see Create New SQL Server Database Dialogue Box.
Choose the OK button.
The database appears in Server Explorer.
I have created a database with 8 tables in SQL Server Management Studio on Windows 7 as a non-admin user. In Visual Studio Express 2010 on the same user I am developing a WPF application that needs to access that database. However, the database file seems to be saved in C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA and I cannot access that file from Visual Studio's Add Connection feature. Although I do have the admin password, files from that directory cannot be added. When I try to add it (after supplying the admin password) I get this message:
You don't have permission to open this file.
Contact the file owner or an administrator to obtain permission.
Furthermore, during various stages of development I will need to create an .exe to send to a colleague for testing. Therefore, from what I understand the database needs to be included as a resource in the Visual Studio project. I have googled all day but found nothing relating to what I thought would be a common scenario. How can I add the database as a VS resource and access it from C#?
Thanks.
As a result of the comments....
SQL Express will provide you with the functionality that you require. Whilst it requires the machine to have the engine installed it does allow instance mode where you can directly attach database files in the connection string.
Additionally SQLExpress can be accessed via the MSSQL Management Studio tool (remember the default instance for this is .\SQLExpress
It was my understanding that I should install the "ADO.NET Driver for MySQL (Connector/NET)", but it doesn't integrate with Visual Web Developer 2010, so I can't select a mysql-connection when creating a new connection from the Database Explorer.
There was VS 2008 Express installed and it configured it under installation. So I uninstalled VS 2008 Express and reinstalled the mysql connector without luck. Then I installed VS 2010 Express, but it didn't integrate there either.
Does anyone know what is wrong? How can I connect to an mysql database from Visual Web Developer 2010?
The ADO driver doesn't seem to integrate with Visual Web Developer Database explorer. You can however make a connection to a MySQL database by using ".Net Framework Data Provider for ODBC". You need to add a dsn reference first. Go to the Control Panel, go to Administration Tools and select Data Sources (ODBC). I added an User DSN by press the Add button. You should fine the MySQL ODBC 5.1 Driver in the list. Select it and you'll get the MySQL Connector/ODBC Data Source Configuration dialog box. Give a name to you Data Source Name (what ever you wnat to call it). Select TCP/IP Server. The server name was left blank since its on my local machine and the port was 3306. Enter the administrative user name the you used when you install MySQL for the User and enter the Password you used. You can then select the database you want. Assuming you installed the sample database, You'll see your database and the sample database in the drop down list. You can then press the Test button and it will verify that you can verify that the database connection works. Once you have that done you can my add a connection to you MySQL database in the Database Explorer by again selecting the ".Net Framework Data Provider for ODBC" You do that by changing the datasoure which bings up a Datasource dialogue box. Then select ".Net Framework Data Provider for ODBC" for the data provider.
In order to program and use mySQLConnection uou need to a a reference to it in Visual Web Developer 2010. To add the reference, click on the menu "Website" and select "Add reference ...". This will bring up the Add Reference dialog box. You would think that the refence would be available in the ".Net" tab, but it isn't. You need to select the "Browse" tab and an navigate to the the MySql assemblies. For me they were located in "C:/Program Files/MySQL/MySQL Connector Net 6.4.3/Assemblies./v4.0. By holding the "shift" or "ctrl" key down you can select all three dll's which are named" MySql.Data.dll, MySql.Data.Entity.dll and MySqlWeb.dll.
I am pretty sure you can use an ODBC connection to accomplish this, you just need to make sure you have the driver installed.