Avatar of deleyd
deleyd
Flag for United States of America asked on

SQL connection string. Where's the database located?

My Asp.Net Razor C# project has a database connection string, and I can't figure out what it's connecting to.


The project has a reference to EntityFramework, and Microsoft SQL, so I'm assuming it's a Microsoft SQL database, somewhere.


The connection string is of the form:

DataSource="ABCDEF"; Initial Catalog="xyzzy"; Persist Security Info=True; ID=zzyzx; Password=uvwxyz"

Open in new window

The "DataSource" is what stumps me. It's not an environment variable, which is what it looks like. A search of the entire project shows this is the only place it is referenced.


In Visual Studio 2019 I open "SQL Server Object Explorer". It lists 3 (LocalDB) databases, none of which are the one. A 4th line has a folder symbol that says "Projects - MyProject" (substitute the actual project name for "MyProject"). That appears to be an empty folder.


Yet the program is definitely connecting to something and pulling data from it. I just can't figure out where it's getting it from.


How can I find out where this database is? How can I examine this database?


ASP.NETDatabasesMicrosoft SQL Server 2008Microsoft SQL Server* Razor

Avatar of undefined
Last Comment
Peter Chan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Pratima

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
manav08

Go to Start and search for ODBC Data Sources
you may find the data source name "ABCDEF" there. You can then select that connection and go to config and get details as to where the source of the database is and what database it connects to

deleyd

ASKER
That was it. I was able to connect to the database in Visual Studio, and then in Microsoft SQL Server.

Now I'm wondering, where is the name of this database, ("ABCDEF"), where is this stored? I searched the registry and found no match. Both Visual Studio and Microsoft SQL Server were unable to give me a list of database name options. I was able to manually enter it though.
Pratima

try this in your code

string databaseName = context.Database.Connection.Database;

Open in new window


Your help has saved me hundreds of hours of internet surfing.
fblack61
Peter Chan

Hi,
Consider to change your connection string to be
                <connectionStrings>
                                <add name="conn2" connectionString="Data Source=192.168.?.?\your_db_instance;Initial Catalog=your_db_schema;Integrated Security=False;User ID=your_db_login;Password=??????" providerName="System.Data.SqlClient"/>
                </connectionStrings>

Open in new window

by applying the above with the relevant IP address of you.