Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using asp.net,C#,VS 2005,and sql server 2005

i have created a setup file for my web project...

i have also installed IIS in my PC..

i have installed my project ...

my web.config contains the following connection string:

XML
<configuration>
    <appSettings/>
    <connectionStrings>
        <add name="conStr" connectionString="Server=localhost;Database=MYDB;Trusted_Connection=Yes;" providerName="System.Data.SqlClient"/>
       
    </connectionStrings>
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="true" defaultLanguage="c#">


but when i type http://localhost/WebSetup1/Firstpage.aspx

it will display a page..

but when i click on page that contains connection with the database it is not shown or executed..

it will give error message like object reference not set to an instance of an object when i do click on insert button...

In short : database connection is not established..

what is the problem..

any solution please..

regards
karan
Posted
Updated 20-May-11 18:38pm
v2
Comments
R. Giskard Reventlov 20-May-11 11:10am    
it may be that the connection string you have applied is not sufficient or you have not granted the requisite permissions for your application to be able to open the database.

Give UID and Password in your connection string

[DATASOURCE=localhost;UID=sa;PWD=;DATABASE=test]

when you deploy your code on IIS did it run ?
have your SQL installed on same machine ?
 
Share this answer
 
v2
Comments
Sanjay J Patolia 21-May-11 2:52am    
My 4.
use this Connection String:

"Data Source=localhost;Initial Catalog=MYDB;Integrated Security=SSPI;"
 
Share this answer
 
Comments
karan joshua 20-May-11 12:41pm    
still not working...same problem...
Mastersev 20-May-11 12:43pm    
post the full error description my friend.
karan joshua 20-May-11 13:10pm    
Server Error in '/WebSetup1' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 101: {
Line 102:
Line 103: rdr.Close();
Line 104:
Line 105: string script = "<script type='text/javascript'>alert('ERROR!!!!Data Not found ...........');</script>";


Source File: c:\Inetpub\wwwroot\WebSetup1\AddStudy.aspx.cs Line: 103

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
AddStudy.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\WebSetup1\AddStudy.aspx.cs:103
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3620; ASP.NET Version:2.0.50727.3618
Shahriar Iqbal Chowdhury/Galib 20-May-11 16:26pm    
what is rdr? clearly rdr is null. Please post full code of Page_Load
karan joshua 21-May-11 0:52am    
if (!IsPostBack)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);

SqlDataReader rdr = null;
SqlDataReader rdr1 = null;

try
{

SqlCommand commandToItemTable = new SqlCommand("select StudyTypeDesc from ItemTable", connection);
SqlCommand commandToItemTable1 = new SqlCommand("select * from ItemTable1", connection);
connection.Open();
rdr = commandToItemTable.ExecuteReader();

while (rdr.Read())
{
StudyTypeDescDropDownList.Items.Add(rdr.GetString(0));

}
rdr.Close();

rdr1 = commandToItemTable1.ExecuteReader();

while (rdr1.Read())
{
ModalityNameDropDownList.Items.Add(rdr1.GetString(0));

}
rdr1.Close();

}
catch(NullReferenceException)
{
rdr.Close();

string script = "<script type='text/javascript'>alert('ERROR!!!!Connection with database failed...........');</script>";
Page page = HttpContext.Current.CurrentHandler as Page;
if (!(page.ClientScript.IsClientScriptBlockRegistered("alert")))
{

page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script);
}
}
catch (Exception ex)
{

rdr.Close();<-------------------------------showing here error

string script = "<script type='text/javascript'>alert('ERROR!!!!Data Not found ...........');</script>";
Page page = HttpContext.Current.CurrentHandler as Page;
if (!(page.ClientScript.IsClientScriptBlockRegistered("alert")))
{

page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script);
}
}
finally
{

connection.Close();

}
Even i remove rdr.close() from catch block it will show that script MessageBox.. saying data Not found..
I you have placed website in IIS then you need to pass userid and password in connection string in place of integrated security =true or trusted_connection


<connectionstrings>
<add name="conStr" connectionstring="Server=localhost;Database=MYDB;User ID=sa; Password=abc" providername="System.Data.SqlClient">

 
Share this answer
 
Comments
karan joshua 21-May-11 4:12am    
actually i dont want to provide user id and password.. It is open access..

It is giving error like:Login Failed To KARAN\ASPNET
Don't Cross post the same question..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900