Results 1 to 20 of 20

Thread: [RESOLVED] [ASP] SQL Connection Error

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Resolved [RESOLVED] [ASP] SQL Connection Error

    I use this source code: http://download-codeplex.sec.s-msft....00&Build=21063 and when I run my web app the sql connection gives errors.

    Name:  HzXBuXH.jpg
Views: 969
Size:  31.5 KB

    I want to use the inbuilt sql express in visual studio and I have also created the relevant database. How do I overcome this error?

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: [ASP] SQL Connection Error

    Are you sure you have created the database in the correct place, it is really hard to read the screenshot (posting the text here would be far easier for people to read) but it looks like it can't find the file. Check the path and make sure it is correct.

    Also why are you catching an exception and then just throwing it? That is exactly the same as not bothering to catch it in the first place.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by PlausiblyDamp View Post
    Are you sure you have created the database in the correct place, it is really hard to read the screenshot (posting the text here would be far easier for people to read) but it looks like it can't find the file. Check the path and make sure it is correct.

    Also why are you catching an exception and then just throwing it? That is exactly the same as not bothering to catch it in the first place.
    Error page: "Server Error in '/' Application.
    The system cannot find the file specified
    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.ComponentModel.Win32Exception: The system cannot find the file specified

    Source Error:


    Line 136: catch (Exception Ex)
    Line 137: {
    Line 138: throw Ex;
    Line 139: }
    Line 140: finally


    Source File: c:\Users\USER\Documents\Visual Studio 2015\files\App_Code\db.cs Line: 138

    Stack Trace:


    [Win32Exception (0x80004005): The system cannot find the file specified]

    [SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
    db.returnDataReader(SqlCommand DRcmd) in c:\Users\USER\Documents\Visual Studio 2015\files\App_Code\db.cs:138
    _Default.Bindquizes() in c:\Users\USER\Documents\Visual Studio 2015\files\Default.aspx.cs:61
    _Default.Page_Load(Object sender, EventArgs e) in c:\Users\USER\Documents\Visual Studio 2015\files\Default.aspx.cs:36
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
    System.Web.UI.Control.OnLoad(EventArgs e) +95
    System.Web.UI.Control.LoadRecursive() +59
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1590.0"

    All files exist and the quizdb was created in sql server object explorer. I'm not sure what this exception is, I'm trying to make this demo work to see if it is what I want it to be and then invest time code-wise.

    This is the sql query I ran:
    Code:
    USE [quizdb]
    GO
    /****** Object:  Table [dbo].[quizdetails]    Script Date: 08/20/2013 12:46:13 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[quizdetails](
    	[id] [int] IDENTITY(1,1) NOT NULL,
    	[name] [nvarchar](1000) NULL,
    	[description] [nvarchar](4000) NULL,
    	[completiondescription] [nvarchar](4000) NULL,
    	[startdate] [datetime] NULL,
    	[enddate] [datetime] NULL,
    	[termsandconditions] [nvarchar](max) NULL,
    	[lastupdated] [datetime] NOT NULL,
     CONSTRAINT [PK_quizdetails] PRIMARY KEY CLUSTERED 
    (
    	[id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    SET IDENTITY_INSERT [dbo].[quizdetails] ON
    INSERT [dbo].[quizdetails] ([id], [name], [description], [completiondescription], [startdate], [enddate], [termsandconditions], [lastupdated]) VALUES (1, N'Sample quiz', N'As a part of the this event we are offering an online quiz. To participate, answer all the questions. You will receive prizes based on your score.', N'Thanks for taking the quiz!!', CAST(0x0000A21400000000 AS DateTime), CAST(0x0000A249018B80D4 AS DateTime), N'<p style="font: 13px/normal arial; color: rgb(69, 85, 96); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; -webkit-text-stroke-width: 0px;">
     This page (together with the documents referred to on it) tells you the terms of use on which you may make use of the websites or websites associated with</p>
    <p style="font: 13px/normal arial; color: rgb(69, 85, 96); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; -webkit-text-stroke-width: 0px;">
     put your company terms and conditons.</p>
    ', CAST(0x0000A22000BD4586 AS DateTime))
    SET IDENTITY_INSERT [dbo].[quizdetails] OFF
    /****** Object:  Table [dbo].[quiz_responses]    Script Date: 08/20/2013 12:46:13 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[quiz_responses](
    	[id] [int] IDENTITY(1,1) NOT NULL,
    	[quizid] [int] NULL,
    	[email] [nvarchar](250) NULL,
    	[name] [nvarchar](500) NULL,
    	[correctanswers] [int] NULL,
    	[wronganswers] [int] NULL,
    	[lastupdated] [datetime] NULL,
     CONSTRAINT [PK_quizresponses] PRIMARY KEY CLUSTERED 
    (
    	[id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET IDENTITY_INSERT [dbo].[quiz_responses] ON
    INSERT [dbo].[quiz_responses] ([id], [quizid], [email], [name], [correctanswers], [wronganswers], [lastupdated]) VALUES (12, 1, N'info@abc.com', N'Test', 3, 2, CAST(0x0000A22000BAB030 AS DateTime))
    INSERT [dbo].[quiz_responses] ([id], [quizid], [email], [name], [correctanswers], [wronganswers], [lastupdated]) VALUES (14, 1, N'w@w.com', N'sample', 5, 0, CAST(0x0000A22000C058E0 AS DateTime))
    INSERT [dbo].[quiz_responses] ([id], [quizid], [email], [name], [correctanswers], [wronganswers], [lastupdated]) VALUES (15, 1, N'abc@xyz.com', N'User', 0, 5, CAST(0x0000A22000C1547A AS DateTime))
    SET IDENTITY_INSERT [dbo].[quiz_responses] OFF
    /****** Object:  Table [dbo].[quiz_questions]    Script Date: 08/20/2013 12:46:13 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[quiz_questions](
    	[id] [int] IDENTITY(1,1) NOT NULL,
    	[quizid] [int] NOT NULL,
    	[questionorder] [int] NULL,
    	[type] [nvarchar](50) NULL,
    	[title] [nvarchar](2000) NULL,
    	[lastupdated] [datetime] NOT NULL,
     CONSTRAINT [PK_quizquestions] PRIMARY KEY CLUSTERED 
    (
    	[id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET IDENTITY_INSERT [dbo].[quiz_questions] ON
    INSERT [dbo].[quiz_questions] ([id], [quizid], [questionorder], [type], [title], [lastupdated]) VALUES (26, 1, 10, N'single', N'Who is the owner of Virgin group of companies?', CAST(0x0000A22000BD324F AS DateTime))
    INSERT [dbo].[quiz_questions] ([id], [quizid], [questionorder], [type], [title], [lastupdated]) VALUES (27, 1, 11, N'single', N'who is the current president of America?', CAST(0x0000A22000AFEDDB AS DateTime))
    INSERT [dbo].[quiz_questions] ([id], [quizid], [questionorder], [type], [title], [lastupdated]) VALUES (28, 1, 12, N'single', N'Where is GMT located?', CAST(0x0000A22000AF1D38 AS DateTime))
    INSERT [dbo].[quiz_questions] ([id], [quizid], [questionorder], [type], [title], [lastupdated]) VALUES (29, 1, 13, N'single', N'Who is the author of The Help?', CAST(0x0000A22000AFCEEF AS DateTime))
    INSERT [dbo].[quiz_questions] ([id], [quizid], [questionorder], [type], [title], [lastupdated]) VALUES (30, 1, 14, N'single', N'Who is the largest producer of milk in the world?', CAST(0x0000A22000B033CD AS DateTime))
    SET IDENTITY_INSERT [dbo].[quiz_questions] OFF
    /****** Object:  Table [dbo].[question_responses]    Script Date: 08/20/2013 12:46:13 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[question_responses](
    	[id] [int] IDENTITY(1,1) NOT NULL,
    	[responseid] [int] NULL,
    	[questionid] [int] NULL,
    	[optionid] [int] NULL,
    	[lastupdated] [datetime] NULL,
     CONSTRAINT [PK_question_responses] PRIMARY KEY CLUSTERED 
    (
    	[id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET IDENTITY_INSERT [dbo].[question_responses] ON
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (56, 12, 26, 66, CAST(0x0000A22000BAB030 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (57, 12, 27, 70, CAST(0x0000A22000BAB030 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (58, 12, 28, 72, CAST(0x0000A22000BAB030 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (59, 12, 29, 76, CAST(0x0000A22000BAB030 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (60, 12, 30, 83, CAST(0x0000A22000BAB030 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (66, 14, 26, 64, CAST(0x0000A22000C058E0 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (67, 14, 27, 70, CAST(0x0000A22000C058E0 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (68, 14, 28, 72, CAST(0x0000A22000C058E0 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (69, 14, 29, 77, CAST(0x0000A22000C058E0 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (70, 14, 30, 83, CAST(0x0000A22000C058E0 AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (71, 15, 26, 66, CAST(0x0000A22000C1547A AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (72, 15, 27, 69, CAST(0x0000A22000C1547A AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (73, 15, 28, 74, CAST(0x0000A22000C1547A AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (74, 15, 29, 76, CAST(0x0000A22000C1547A AS DateTime))
    INSERT [dbo].[question_responses] ([id], [responseid], [questionid], [optionid], [lastupdated]) VALUES (75, 15, 30, 80, CAST(0x0000A22000C1547A AS DateTime))
    SET IDENTITY_INSERT [dbo].[question_responses] OFF
    /****** Object:  Table [dbo].[question_options]    Script Date: 08/20/2013 12:46:13 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[question_options](
    	[id] [int] IDENTITY(1,1) NOT NULL,
    	[questionid] [int] NOT NULL,
    	[questionoption] [nvarchar](500) NULL,
    	[lastupdated] [datetime] NULL,
     CONSTRAINT [PK_question_options] PRIMARY KEY CLUSTERED 
    (
    	[id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET IDENTITY_INSERT [dbo].[question_options] ON
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (64, 26, N'Sir Richard Branson', CAST(0x0000A22000ABFEA7 AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (65, 26, N'Emma Harrison', CAST(0x0000A22000ABFEA7 AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (66, 26, N'Geoff Dyson', CAST(0x0000A22000AD75E6 AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (67, 26, N'Jane Cavanagh', CAST(0x0000A22000ABFEA7 AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (68, 27, N'George Bush', CAST(0x0000A22000AEB905 AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (69, 27, N'David Cameron', CAST(0x0000A22000AEB905 AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (70, 27, N'Barack Obama', CAST(0x0000A22000AEB905 AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (71, 27, N'Joachim Gauck', CAST(0x0000A22000AEB905 AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (72, 28, N'London', CAST(0x0000A22000AF0CCD AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (73, 28, N'Dubai', CAST(0x0000A22000AF0CCD AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (74, 28, N'Tokyo', CAST(0x0000A22000AF0CCD AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (75, 28, N'Honkong', CAST(0x0000A22000AF0CCD AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (76, 29, N'Dan Brown', CAST(0x0000A22000AFBFDA AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (77, 29, N'Kathryn Stockett', CAST(0x0000A22000AFBFDA AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (78, 29, N'Alfred Hitchcock', CAST(0x0000A22000AFBFDA AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (79, 29, N'charles Dickens', CAST(0x0000A22000AFBFDA AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (80, 30, N'China', CAST(0x0000A22000B033CD AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (81, 30, N'America', CAST(0x0000A22000B033CD AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (82, 30, N'Brazil', CAST(0x0000A22000B033CD AS DateTime))
    INSERT [dbo].[question_options] ([id], [questionid], [questionoption], [lastupdated]) VALUES (83, 30, N'India', CAST(0x0000A22000B033CD AS DateTime))
    SET IDENTITY_INSERT [dbo].[question_options] OFF
    /****** Object:  Table [dbo].[question_answer]    Script Date: 08/20/2013 12:46:13 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[question_answer](
    	[id] [int] IDENTITY(1,1) NOT NULL,
    	[questionid] [int] NOT NULL,
    	[optionid] [int] NOT NULL,
    	[lastupdated] [datetime] NULL,
     CONSTRAINT [PK_question_answer] PRIMARY KEY CLUSTERED 
    (
    	[id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET IDENTITY_INSERT [dbo].[question_answer] ON
    INSERT [dbo].[question_answer] ([id], [questionid], [optionid], [lastupdated]) VALUES (11, 26, 64, CAST(0x0000A22000BD324F AS DateTime))
    INSERT [dbo].[question_answer] ([id], [questionid], [optionid], [lastupdated]) VALUES (12, 27, 70, CAST(0x0000A22000AFEDDB AS DateTime))
    INSERT [dbo].[question_answer] ([id], [questionid], [optionid], [lastupdated]) VALUES (13, 28, 72, CAST(0x0000A22000AF1D38 AS DateTime))
    INSERT [dbo].[question_answer] ([id], [questionid], [optionid], [lastupdated]) VALUES (14, 29, 77, CAST(0x0000A22000AFCEEF AS DateTime))
    INSERT [dbo].[question_answer] ([id], [questionid], [optionid], [lastupdated]) VALUES (15, 30, 83, CAST(0x0000A22000B036B5 AS DateTime))
    SET IDENTITY_INSERT [dbo].[question_answer] OFF
    /****** Object:  ForeignKey [FK_question_answer_quizquestions]    Script Date: 08/20/2013 12:46:13 ******/
    ALTER TABLE [dbo].[question_answer]  WITH CHECK ADD  CONSTRAINT [FK_question_answer_quizquestions] FOREIGN KEY([questionid])
    REFERENCES [dbo].[quiz_questions] ([id])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[question_answer] CHECK CONSTRAINT [FK_question_answer_quizquestions]
    GO
    /****** Object:  ForeignKey [FK_question_options_quizquestions]    Script Date: 08/20/2013 12:46:13 ******/
    ALTER TABLE [dbo].[question_options]  WITH CHECK ADD  CONSTRAINT [FK_question_options_quizquestions] FOREIGN KEY([questionid])
    REFERENCES [dbo].[quiz_questions] ([id])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[question_options] CHECK CONSTRAINT [FK_question_options_quizquestions]
    GO
    /****** Object:  ForeignKey [FK_question_responses_quizresponses]    Script Date: 08/20/2013 12:46:13 ******/
    ALTER TABLE [dbo].[question_responses]  WITH CHECK ADD  CONSTRAINT [FK_question_responses_quizresponses] FOREIGN KEY([responseid])
    REFERENCES [dbo].[quiz_responses] ([id])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[question_responses] CHECK CONSTRAINT [FK_question_responses_quizresponses]
    GO
    /****** Object:  ForeignKey [FK_quizquestions_quizdetails]    Script Date: 08/20/2013 12:46:13 ******/
    ALTER TABLE [dbo].[quiz_questions]  WITH CHECK ADD  CONSTRAINT [FK_quizquestions_quizdetails] FOREIGN KEY([quizid])
    REFERENCES [dbo].[quizdetails] ([id])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[quiz_questions] CHECK CONSTRAINT [FK_quizquestions_quizdetails]
    GO
    /****** Object:  ForeignKey [FK_quizresponses_quizdetails]    Script Date: 08/20/2013 12:46:13 ******/
    ALTER TABLE [dbo].[quiz_responses]  WITH CHECK ADD  CONSTRAINT [FK_quizresponses_quizdetails] FOREIGN KEY([quizid])
    REFERENCES [dbo].[quizdetails] ([id])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[quiz_responses] CHECK CONSTRAINT [FK_quizresponses_quizdetails]
    GO
    I also added and converted the virtual directory to application in IIS manager.
    Last edited by NewWorldOrder; Oct 25th, 2017 at 05:05 AM.

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: [ASP] SQL Connection Error

    My first guess would be a problem with the connection string or the sql server isn't running.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: [ASP] SQL Connection Error

    Thread moved from the 'ASP, VB Script' forum to the 'ASP.Net' forum

    Quote Originally Posted by PlausiblyDamp View Post
    My first guess would be a problem with the connection string or the sql server isn't running.
    They are definitely likely to be the cause of the issue.

    Once those are checked (and fixed if apt), if the problem still exists and the database server is on a different machine to the web site, it is wise to check "that SQL Server is configured to allow remote connections." as mentioned in the error message... Exactly how you do that depends on the version of SQL Server you are using.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by si_the_geek View Post
    Thread moved from the 'ASP, VB Script' forum to the 'ASP.Net' forum

    They are definitely likely to be the cause of the issue.

    Once those are checked (and fixed if apt), if the problem still exists and the database server is on a different machine to the web site, it is wise to check "that SQL Server is configured to allow remote connections." as mentioned in the error message... Exactly how you do that depends on the version of SQL Server you are using.
    I use sql object explorer, does that count as sql server? I want to test this app locally on firefox via visual studio, so I don't know how to link sql server or if sql object explorer is one of them. Can you help me?

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by NewWorldOrder View Post
    I use sql object explorer, does that count as sql server?
    I believe so, but it would help to see a screenshot of that part of the window (partly so we can see object names).

    I want to test this app locally on firefox via visual studio,
    In that case what I mentioned before isn't relevant, we just need to work out the details.

    Can you help me?
    Somewhere in your program is a Connection String (most likely to be something like "Server=****;Database=****;Trusted_Connection=True;" or "Server=****;Database=****;User Id=****;Password=****;" ), find it and tell us what it contains... free free to mask the username/password.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by si_the_geek View Post
    I believe so, but it would help to see a screenshot of that part of the window (partly so we can see object names).

    In that case what I mentioned before isn't relevant, we just need to work out the details.

    Somewhere in your program is a Connection String (most likely to be something like "Server=****;Database=****;Trusted_Connection=True;" or "Server=****;Database=****;User Id=****;Password=****;" ), find it and tell us what it contains... free free to mask the username/password.



    Code:
    <configuration>
      <configSections/>
      <connectionStrings>
        <remove name="quizConnectionString"/>
        <add name="quizConnectionString" connectionString="server=localhost;database=quizdb;user=;pwd=" providerName="System.Data.SqlClient"/>
      </connectionStrings>
      <system.web>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          </assemblies>
        </compilation>
        <globalization uiCulture="en-GB" culture="en-GB"/>
        <authentication mode="Forms">
          <forms loginUrl="~/Login" timeout="2880" defaultUrl="~/"/>
        </authentication>
        <customErrors mode="Off"/>
    ..
    Attached Images Attached Images  
    Last edited by NewWorldOrder; Oct 25th, 2017 at 06:28 PM.

  9. #9
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: [ASP] SQL Connection Error

    The connection string in your config file isn't the same as the connection string you are using in the visual studio explorer, you can just make out in your screenshot that is starts with a different DataSource - try making your config file use the same as VS and see if that works.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by PlausiblyDamp View Post
    The connection string in your config file isn't the same as the connection string you are using in the visual studio explorer, you can just make out in your screenshot that is starts with a different DataSource - try making your config file use the same as VS and see if that works.
    Which connection string should I use?

  11. #11
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: [ASP] SQL Connection Error

    If the one you are using in your config file doesn't work but the one you are using in visual studio does I would suggest using the one from visual studio. It looks like the one in Visual Studio is using (localdb)\<something or other I can't make out from the screenshot> which is typical when you are using the included sql engine, your connection string is trying to access just localhost which isn't the same thing.

    I would try using the one from the properties window and see if that works.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by PlausiblyDamp View Post
    If the one you are using in your config file doesn't work but the one you are using in visual studio does I would suggest using the one from visual studio. It looks like the one in Visual Studio is using (localdb)\<something or other I can't make out from the screenshot> which is typical when you are using the included sql engine, your connection string is trying to access just localhost which isn't the same thing.

    I would try using the one from the properties window and see if that works.
    Good point. In properties I see "Connection String | Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover =False" I tried "localdb", but I get the same error .
    Last edited by NewWorldOrder; Oct 29th, 2017 at 06:41 AM.

  13. #13
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: [ASP] SQL Connection Error

    Code:
     <add name="quizConnectionString" connectionString="server=localhost;database=quizdb;user=;pwd=" providerName="System.Data.SqlClient"/>
    I noticed you have empty user and pwd in your connection string. How about adding correct values for those two?

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by KGComputers View Post
    Code:
     <add name="quizConnectionString" connectionString="server=localhost;database=quizdb;user=;pwd=" providerName="System.Data.SqlClient"/>
    I noticed you have empty user and pwd in your connection string. How about adding correct values for those two?

    - kgc
    I havent set any credentials.

  15. #15
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by NewWorldOrder View Post
    Good point. In properties I see "Connection String | Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover =False" I tried "localdb", but I get the same error .
    So did you copy the entire connection string from the properties window into your config file, replacing the existing connection string?

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by PlausiblyDamp View Post
    So did you copy the entire connection string from the properties window into your config file, replacing the existing connection string?
    All of it? No. Just "localdb"

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: [ASP] SQL Connection Error

    Using all of it is important, because the entire connection string is what specifies how to connect to the database (including what type of database it is, where it is, what it is called, what login details to use, etc).

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by si_the_geek View Post
    Using all of it is important, because the entire connection string is what specifies how to connect to the database (including what type of database it is, where it is, what it is called, what login details to use, etc).
    So, how exactly should my connection string look like?

  19. #19
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: [ASP] SQL Connection Error

    Quote Originally Posted by NewWorldOrder View Post
    So, how exactly should my connection string look like?
    If the one in Visual Studio's properties window works then I would say make it look exactly like the one in Visual Studio's properties window, because that one works. You can just copy and paste it from the properties window into your config file to make things easier.

    Back in post #15 you posted the entire connection string from Visual Studio's properties window, the one you said works, so try using that connection string.

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Aug 2017
    Posts
    26

    Re: [ASP] SQL Connection Error

    I used this string and it worked
    Code:
    <add name="QuizConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=quizdb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width