Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2010, 07:01 AM
Registered User
 
Join Date: Oct 2007
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default SQL Server Express doesn't work.

I try to open the SQL Server Express database file "sample.mdf" but it doesn't work.
Here is the code:
-----------------------------------------------------------------------------------------------------

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//OleDb-ACCESS
//--------------
//OleDbConnection con = new OleDbConnection();
//string comPath = Server.MapPath("~" + @"\") + @"app_Data\webTest.mdb";
//string coS = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + comPath;


//SqlClient-SQL server express
//------------------------------
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
string comPath = Server.MapPath("~" + @"\") + @"app_Data\sample.mdf";
string coS = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + comPath + ";Integrated Security=True;User Instance=False;";

//OleDb-SQL server express
//-------------------------
//OleDbConnection con = new OleDbConnection();
//string comPath = Server.MapPath("~" + @"\") + @"app_Data\sample.mdf";
//string coS = "Provider=SQLOLEDB.1;" + "Data Source=" + comPath;


con.ConnectionString = coS;
con.Open();

}
}
-------------------------------------------------------------------------------------------------------
1. Code OleDb-ACCESS (commented) works OK.
2 . When I run the code in section: SqlClient-SQL Server express, I get error:
Server Error in '/myWeb/trySqlServer' Application.
CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file C:\MyPrograms\web\trySqlServer\app_Data\sample.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file C:\MyPrograms\web\trySqlServer\app_Data\sample.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

3. When I run the code in section: OleDB-Sql server express I get error:

Invalid authorization specification
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Invalid authorization specification


What should I do to open the SQL Server database "sample.mdf"?

Thank you
[FONT='Times New Roman','serif']Hezi[/FONT]
 
Old February 9th, 2010, 09:40 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Firstly check to make sure a normal .aspx page runs

Try setting up the connection in the web.config file.

<connectionStrings>
<
addname="ConnectionString"connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\sample.mdf;Integrated Security=True;User Instance=True"providerName="System.Data.SqlClient"/>
</
connectionStrings>

Make sure that sample.mdf is in the App_Data folder of your application.

Place a sqldatasource on the page.

PS The first option calls webTest.mdb and not sample.mdf. Im assuming this is an access file from a previous application and the inclusion was just for information


__________________
Try our latest project www.nobanx.com Currency Exchange for members
 
Old February 9th, 2010, 11:15 AM
Registered User
 
Join Date: Oct 2007
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default SQL Server Express doesn't work

Thank you very much. Now it works.
How should I change it to work with SQL Server 2005 (Not express)?
Thanks,
Hezi
 
Old February 9th, 2010, 11:22 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Data Source=.\SQLEXPRESS;AttachDbFilename

Change SQLEXPRESS to your server installation name (sorry I've forgotten the correct term, can anyone else remind me).
__________________
Try our latest project www.nobanx.com Currency Exchange for members
 
Old February 9th, 2010, 12:21 PM
Registered User
 
Join Date: Oct 2007
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default SQL Server Express doesn't work

If I intend to install the code in severel servers should I have to write different config files for each server(each file with a different "data source=server installation name")?
Thanks,
hezi
 
Old February 9th, 2010, 01:03 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

I have always placed a unique web.config with each domain.

I'm assuming each system you are talking about is on a web server and not a standalone application.

I Only work with web applications and not standalone applications so can only make suggestions for this type of installation.

Hope this helps.
__________________
Try our latest project www.nobanx.com Currency Exchange for members





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 vs SQL Server Express Rachel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 May 9th, 2009 01:08 PM
Upgrade SQL Express to SQL Server timeware SQL Server 2005 2 August 27th, 2007 02:37 PM
SQL SERVER EXPRESS rht886 SQL Server 2005 1 March 21st, 2007 08:44 AM
VB Express and SQL server on remote server questio HoosierDaddy61 Visual Basic 2005 Basics 0 February 22nd, 2006 11:27 AM
Accessing a SQL Server Express DB thru VB Express djelavic SQL Server 2005 2 February 21st, 2006 07:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.