Re: How do you run a .sql script?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Continuing to work this - I managed somehow to get the database and tables
set up, but when I try to run the project I get this error message:

Server Error in '/MovieReviews' Application.
--------------------------------------------------------------------------------
An error has occurred while establishing a connection to the server. When
connecting to SQL Server 2005, this failure may be caused by the fact that
under the default settings SQL Server does not allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to
SQL Server)
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: An error has occurred
while establishing a connection to the server. When connecting to SQL
Server 2005, this failure may be caused by the fact that under the default
settings SQL Server does not allow remote connections. (provider: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): An error has occurred while establishing a
connection to the server. When connecting to SQL Server 2005, this failure
may be caused by the fact that under the default settings SQL Server does
not allow remote connections. (provider: Named Pipes Provider, error: 40 -
Could not open a connection to SQL Server)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) +117
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) +346
System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner,
Boolean& failoverDemandDone, String host, String failoverPartner, String
protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean
encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection
owningObject, Boolean aliasLookup) +1093
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection
owningObject, SqlConnectionString connectionOptions, String newPassword,
Boolean redirectedUserInstance) +1083
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo, String
newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
+272
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection
owningConnection) +687
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options) +82
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection
owningObject) +558
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject) +126
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject) +651
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection) +160
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory) +122
System.Data.SqlClient.SqlConnection.Open() +228
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
ConnectionState& originalState) +49
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior) +162
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior) +307
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
+152
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments
arguments) +2868
System.Web.UI.WebControls.Repeater.GetData() +57
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean
useDataSource) +292
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +70
System.Web.UI.WebControls.Repeater.DataBind() +85
System.Web.UI.WebControls.Repeater.EnsureDataBound() +83
System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +27
System.Web.UI.Control.PreRenderRecursiveInternal() +148
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4437
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.210

Please offer more sage advice!
Thanks,
Mich

"Chris Anderson" <tg[no-spam]@tannagh.[spam-a-less].com> wrote in message
news:2fc3047d6c0f8c97243dc74a1d1@xxxxxxxxxxxxxxxxxxxxxxx
Oddly enough, they are the result of a single error.
It looks like the user ASPNET isn't setup in the server. Easily fixable
though. Maybe.

Is ASP.NET installed on the computer where SQL is?


Chris Anderson VB-MVP


Installed Microsoft SQL Server 2005 Express Edition with Advanced
Services and Microsoft SQL Server 2005 Express Edition Toolkit.
Double-clicked the .sql file and the SQL Server Management Studio
window opened. I made sure Master was selected in Object Explorer (I
didn't see a drop-down box at the top of the screen) and executed the
script. I got these error messages:

Msg 15401, Level 11, State 1, Procedure sp_grantlogin, Line 49
Windows NT user or group 'M399\SQLEXPRESS\ASPNET' not found. Check the
name
again.
Msg 15401, Level 16, State 1, Line 1
Windows NT user or group 'M399\SQLEXPRESS\ASPNET' not found. Check the
name
again.
Msg 15410, Level 11, State 1, Procedure sp_addrolemember, Line 75
User or role 'M399\SQLEXPRESS\ASPNET' does not exist in this database.
Msg 15410, Level 11, State 1, Procedure sp_addrolemember, Line 75
User or role 'M399\SQLEXPRESS\ASPNET' does not exist in this database.
What do they mean, and how do I correct them? There are only 42 lines
in
the script... My PC name is M399
Thanks for your great advice so far,
Mich
"Chris Anderson" <tg[no-spam]@tannagh.[spam-a-less].com> wrote in
message news:2fc3047d60128c970d3ce969837@xxxxxxxxxxxxxxxxxxxxxxx

Ick.... on MSDN... search for SQL Server Management Studio.... it
should be in the first few hits that come back.

Chris Anderson VB-MVP

Under Programs I have:
Microsoft SQL Server 2005
Configuration Tools
SQL Server Configuration Manager
SQL Server Error and Usage Reporting
SQL Server Surface Area Configuration
Documentation and Tutorials
Samples Directory
Where would I find SQL Server Management Studio?
"Chris Anderson" <tg[no-spam]@tannagh.[spam-a-less].com> wrote in
message news:2fc3047d5f908c970cd6f880a98@xxxxxxxxxxxxxxxxxxxxxxx

What version of SQL Server are you using?
2000? or 2005?
If you are using 2000, look for something called Query Analyzer.
It'll ask you to login, I'm guessing that the default settings
should
work (it's been a while since I've worked with a fresh install of
it). Then you can 1) Drag and drop the .SQL file into the screen
there. That will open the file up. Or 2) Select File -> Open from
the
menu (or use Ctrl-Shift-P from the keyboard). Find the file and
click
Ok. that will load the file as well.
If you are using SQL 2005, look for SQL Server Management Studio
(SSMS). Again, default login creds should be OK. Once you've got
that open, Ctrl-O will open the "Open File" dialog... select the
file, click OK (or Open). It'll ask for the login credentials
again. Again, they should be OK.

Once the file is opened (for either 2000 or 2005), make sure the
current database is Master (should be in a drop-down box at the top
of the screen). Press F5 to run the script.

Chris Anderson VB-MVP

I have found an online VS tutorial with a downloaded solution.
One
of
the
downloaded files is a script to run to populate a database. I
have
Visual
Studio 2005 standard. The script is called PopulateTables.sql and
contains
statements like:
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
N'orders')
DROP DATABASE orders
GO
CREATE DATABASE orders
GO
USE orders
GO
etc and it adds a bunch of records.
My question is: How do I run this? If I double-click in Explorer
it
just opens in Notepad. Do I run this from Visual Studio? I have
the
SQL Server that came with Visual Studio, but I don't seem to have
many
options to do anything from it when I open it. I'm completely
lost
-
what do I do to create the database and tables so I can use it on
this
tutorial (which assumes I know what to do?)
Thanks,
Mich




.



Relevant Pages

  • Re: My Book is Incomplete Regarding SQL Commands ;-(
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... Create a Connection object and pass in a ConnectionString to ... manage the database table you reference. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: (Newbie)Application Roles
    ... level: the database itself. ... SQL Server accommodates these needs through the use of application ... the user's connection through a specific application. ... the connection permanently loses all permissions applied to ...
    (microsoft.public.sqlserver.security)
  • Re: Help! Set up Windows Group to access application
    ... The connection string for a trusted connection is: ... --add login as database user ... SQL Server MVP ... If you have troubles with finding your ways in Crystal Reports, ...
    (microsoft.public.sqlserver.security)
  • Re: Concurrent database access in SQL 2005 Mobile
    ... opening one connection for the lifetime of the app and keeping it open seems ... What version of SQL CE are you using? ... Are you accessing the database from an app written in C++? ... then opens his work forms and it's in those ...
    (microsoft.public.sqlserver.ce)
  • Re: My Book is Incomplete Regarding SQL Commands ;-(
    ... Visual Studio but not to VS 2003. ... Create a Connection object and pass in a ConnectionString to address ... manage the database table you reference. ... Yep, my latest book can help too, but mostly if you're targeting SQL Server ...
    (microsoft.public.dotnet.framework.adonet)