SausageBuscuit
SausageBuscuit

Reputation: 1296

Change default database with ASP.NET Web Application

I have created a C# ASP.NET web site in Visual Studio 2010. Pretty much all of the other kinks have been worked out, but the site is to have a database that stores certain user data. I have this DB stored on a drive on a SQL Server (let's say it's on the E drive of a server with an IP of 192.168.6.100). We have a DSN on this server set up to be used with this db. I used a Visual Studio template for my site (just the regular C# ASP.NET template), so it had an account db and login/register sites pre-made. The default DB that they give you is in an App_Data folder with the name aspnetdb.mdf. In the web.config file, I've got the following connection string.

<connectionStrings>
<add name="ApplicationServices"
     connectionString="data source=.\SQLEXPRESS;Integrated
     Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
     providerName="System.Data.SqlClient" />
</connectionStrings>

My question is what is going to be the easiest way to convert the default code so that it will allow the other database to be used, but still reside on the 192.168.6.100 server? I don't want to use the built in DB because there are going to be additional tables that I need to create and store. I would have figured I could just change the connection string and the methods that access data in the DB, but can't find the proper syntax given the location of the db. Also, in the default template, I don't see anywhere where the calls are being made to actually save the data into the specified database (can't find any SQL statements in the backend code that store to aspnetdb.mdf). Does anyone know where this takes place? Should I just scrap the default setup and make my own login/register pages?

Upvotes: 2

Views: 7245

Answers (1)

SausageBuscuit
SausageBuscuit

Reputation: 1296

Got this months ago, but figured I wouldn't leave it unanswered. I was attempting to use a DSN instead of the IP, which either these config files didn't seem to like this or I didn't configure it properly. Either way, the connection string below worked.

<connectionStrings>
    <add name="ApplicationServices"  connectionString="datasource=192.168.6.100;
    database=databasename;user=username;password=****;
    Integrated Security=SSPI;"
    providerName="System.Data.SqlClient" />
</connectionStrings>

Upvotes: 5

Related Questions