Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag 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?


ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
User generated imageUser generated image
Avatar of 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.
try this in your code

string databaseName = context.Database.Connection.Database;

Open in new window


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.