Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Selecting The Database to Use in ASP.NET code...

This should be an easy one.  I've learned how to use ASP.NET to modify the Northwind Database.  Now, I want to write a page to modify a DIFFERENT database, but I don't know how to identify it.

You see, in the ASP.NET code, Northwind is identified as "NWind".  Nowhere in the database's information or properties am I able to find this name.  I need to use the same-level of name for my new database, but I don't know what name that would be.  How do I find out?
0
brassmonkeyboy
Asked:
brassmonkeyboy
  • 3
  • 2
1 Solution
 
MikeMCSDCommented:
Is this an Access database or SQL Server?
You can use the Server Explorer (above the toolbox on the left)
in Visual Studio to access databases that are local or on another server.

Or you can access the new database in Code like this:
This example uses SQL Server:

ConnectionString ="server=localhost;Initial Catalog=MyData;User Id=sa;Password="

 Dim connection As New SqlConnection(ConnectionString )
      Dim command As New SqlCommand("GetCatInDept", connection)
      command.CommandType = CommandType.StoredProcedure
      command.Parameters.Add("@DepartmentID", SqlDbType.Int, 4)
      command.Parameters("@DepartmentID").Value = departmentId
      Try
         connection.Open()
         Return command.ExecuteReader(CommandBehavior.CloseConnection)
      Catch e As Exception
         connection.Close()
         Throw e
      End Try
0
 
brassmonkeyboyAuthor Commented:
Hrm..I don't think I was as clear as I should have been.  I have connected to it fine through the Server Explorer (It's sql btw).

The code I've been using to access the Northwind database in code is like this:

Dim strConnection As String = ConfigurationSettings.AppSettings("NWind")

Now, I just want to use this to connect to my db instead of Northwind.  But I can't find a single occurance of the name "NWind" so I can figure out just how to identify my new database.  What does the "NWind" refer to precisely?
0
 
MikeMCSDCommented:
My only guess is that it could be a  DSN  . . .  
Control Panel, Admin Tools, Data Sources (ODBC)
See if it is listed in there.

So you are saying you want to replace your database name with NWind?

ConfigurationSettings.AppSettings("YourDatabaseName")

0
 
brassmonkeyboyAuthor Commented:
Nothing's listed in the DSN list at all...

Yeah, I want to do this:

ConfigurationSettings.AppSettings("YourDatabaseName")

But I don't know what exactly to put in for "YourDatabaseName" because I don't know the source of the NWind name.
0
 
MikeMCSDCommented:
open up your Web.config file .  .
look for something like this:

<configuration>
    <appSettings>
<add key="NWind" value="server=localhost;Initial Catalog=Northwind;User Id=sa;Password=" />
    </appSettings>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now