Hi, Is it possible to have more than one database / compact sql databases in a website? I know my host has support for webmatrix and I"d like to use the login database / starter for just that, and then add another database for something else. Is that possible?
Is there a link to using SQL server with Webmatrix? I can't seem to find the article I thought I saw on here?
Hi, I looked at this again, and I'm confused. I mean is it possible to have more than one SDF File with each web site ? I'm assuming my host would have to support it, but I'm wondering if Webmatrix will allow it?
Is it possible to have more than one database / compact sql databases in a website?
I think Yes it is, as long as the db reside in a single .sdf file, you can open the connection with the one you want using Database.Open();
You can use as many databases as you want in your website. By the way, only one database can reside in one .sdf file.
For example, the following code opens two databases/sdf files (Northwind.sdf and SecondDb.sdf) and copies the content of Customers from Northwind to Customers2 in SecondDb:
@{
var db1 = Database.Open("Northwind");
var db2 = Database.Open("SecondDb");
var data = db1.Query("SELECT * FROM Customers");
var count = 0;
foreach(var row in data)
{
count += db2.Execute(@"INSERT INTO Customers2(CompanyName, Address, City, PostalCode, Country)
VALUES (@0, @1, @2, @3, @4)", row.CompanyName, row.Address, row.City, row.PostalCode,
row.Country);
}
}
Marked as answer by DotNetTim on Nov 18, 2012 09:46 PM
Thank you so much GM. I really appreciate it. ONe more question. Can you open a remote database such as SQL server and a local Database such as compact SDF file at the same time in a local file / folder website using Webmatrix?
Can you open a remote database such as SQL server and a local Database such as compact SDF file at the same time in a local file / folder website using Webmatrix?
You can do it without problems.
Marked as answer by DotNetTim on Nov 19, 2012 03:36 PM
DotNetTim
Member
384 Points
137 Posts
More than one database / Compact database with a webmatrix razor site?
Nov 15, 2012 09:42 PM|LINK
Hi, Is it possible to have more than one database / compact sql databases in a website? I know my host has support for webmatrix and I"d like to use the login database / starter for just that, and then add another database for something else. Is that possible?
Is there a link to using SQL server with Webmatrix? I can't seem to find the article I thought I saw on here?
Thanks
Tim
dow7
Member
738 Points
452 Posts
Re: More than one database / Compact database with a webmatrix razor site?
Nov 15, 2012 09:53 PM|LINK
I think Yes it is, as long as the db reside in a single .sdf file, you can open the connection with the one you want using Database.Open();
http://www.microsoft.com/web/post/connecting-to-a-sql-server-or-mysql-database-in-webmatrix
DotNetTim
Member
384 Points
137 Posts
Re: More than one database / Compact database with a webmatrix razor site?
Nov 15, 2012 10:00 PM|LINK
Thank you so much. I really appreciate it..
Tim
DotNetTim
Member
384 Points
137 Posts
Re: More than one database / Compact database with a webmatrix razor site?
Nov 18, 2012 05:58 AM|LINK
Hi, I looked at this again, and I'm confused. I mean is it possible to have more than one SDF File with each web site ? I'm assuming my host would have to support it, but I'm wondering if Webmatrix will allow it?
Tim
GmGregori
Contributor
5564 Points
749 Posts
Re: More than one database / Compact database with a webmatrix razor site?
Nov 18, 2012 08:06 AM|LINK
You can use as many databases as you want in your website. By the way, only one database can reside in one .sdf file.
For example, the following code opens two databases/sdf files (Northwind.sdf and SecondDb.sdf) and copies the content of Customers from Northwind to Customers2 in SecondDb:
@{ var db1 = Database.Open("Northwind"); var db2 = Database.Open("SecondDb"); var data = db1.Query("SELECT * FROM Customers"); var count = 0; foreach(var row in data) { count += db2.Execute(@"INSERT INTO Customers2(CompanyName, Address, City, PostalCode, Country) VALUES (@0, @1, @2, @3, @4)", row.CompanyName, row.Address, row.City, row.PostalCode, row.Country); } }DotNetTim
Member
384 Points
137 Posts
Re: More than one database / Compact database with a webmatrix razor site?
Nov 18, 2012 09:47 PM|LINK
Thank you so much GM. I really appreciate it. ONe more question. Can you open a remote database such as SQL server and a local Database such as compact SDF file at the same time in a local file / folder website using Webmatrix?
Thanks so much.
Tim
GmGregori
Contributor
5564 Points
749 Posts
Re: More than one database / Compact database with a webmatrix razor site?
Nov 19, 2012 11:42 AM|LINK
You can do it without problems.