Showing posts with label recieve. Show all posts
Showing posts with label recieve. Show all posts

Thursday, March 22, 2012

cant access the datasource control

When I put a sqldatasource in my page and want to configure it and add a new connection to it I recieve this error : "object reference not set to an instance of an object" . Do you have any idea about solving this problem. please help me Thanks

Hi,

when asking a question about code or when you get an error always try to provide therelevant pieces of code and the error message that you get. This helps the people around here to better help you out.

Grz, Kris.

|||

My program has only a simple datagrid that should get data from a sql table and show it.This is only a test after changing the IIS settings. You can see my code here:

When I run this program I don't recieve any error but the explorer shows the blank page. When I try making connectionstring via sqldatasource I recieve that error:"the object reference...".thanks for helping

public

partialclassado1 : System.Web.UI.Page

{

privatevoid bindgrid()

{

string conStr ="Data Source=.;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa";SqlConnection conn =newSqlConnection(conStr);// Open the connection

conn.Open();

// Create a data adapter objectSqlDataAdapter adapter =newSqlDataAdapter("SELECT * FROM testt", conn);DataSet ds =newDataSet();

adapter.Fill(ds);

GridView1.DataBind();

conn.Close();

}

protectedvoid Page_Load(object sender,EventArgs e)

{

if (!IsPostBack)

{

bindgrid();

}}}

///////////////////////////////

the body of aspx file is here:

<

body><formid="form1"runat="server"><div> <asp:SqlDataSourceID="SqlDataSource1"runat="server"></asp:SqlDataSource><asp:GridViewID="GridView1"runat="server"></asp:GridView></div></form>

</

body>

/////////////////////////////////////

|||

Hi,

hsharifi:

publicpartialclassado1 : System.Web.UI.Page

{

privatevoid bindgrid()

{

string conStr ="Data Source=.;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa";

SqlConnection conn =newSqlConnection(conStr);

// Open the connection

conn.Open();

// Create a data adapter objectSqlDataAdapter adapter =newSqlDataAdapter("SELECT * FROM testt", conn);DataSet ds =newDataSet();

adapter.Fill(ds);

GridView1.DataBind();

conn.Close();

}

protectedvoid Page_Load(object sender,EventArgs e)

{

if (!IsPostBack)

{

bindgrid();

}}}

///////////////////////////////

the body of aspx file is here:

<

body><formid="form1"runat="server"><div> <asp:SqlDataSourceID="SqlDataSource1"runat="server"></asp:SqlDataSource><asp:GridViewID="GridView1"runat="server"></asp:GridView></div></form>

</

body>

/////////////////////////////////////

it seems like you're trying to do 2 things here: you want to use code & the SqlDataSource control together, that's a no go.

Get rid of the SqlDataSource control on your page and in the codefile, just before you call the DataBind() method place this line:

GridView1.DataSource = ds;
GridView1.DataBind();

Grz, Kris.

|||

Hi Xlll ,and thank you for replying me.

I did the thing that you said but my problem is still going on. After running my program the browser shows a blank page. I had to change many settings in IIS, do you think this problem is related to these changes or may be I should reinstall vs.net after that.

I would be glad to hear your opinion. Thanks

|||

Hi,

before re?nstalling you can first let the aspnet_regiis -i tool do its work to set the correct settings for the correct framework in IIS.

Something else that you can try: place a TextBox, Button and Label control on a webform. In the Button Click event you place this code:

Label1.Text = TextBox1.Text

and see if it executes well on your server. It's probably something stupid but I like to use such scenario's to quickly test out if ASP.NET is installed properly on a machine.

Grz, Kris.

Thursday, March 8, 2012

Cannot truncate table because it is being referenced by another ob

I recieve the following error after configuring replication between two servers. I am not sure how to resolve it. Does anyone have any ideas?
Thanks in advance,
Peter
Cannot TRUNCATE TABLE 'TwAccType' because it is being referenced by object 'TwAccTypeUserNotNull'.
(Source: TUMIME2 (Data source); Error number: 3729)
Event Type:Information
Event Source:SQLSERVERAGENT
Event Category:Job Engine
Event ID:203
Date:6/15/2004
Time:10:42:06 AM
User:N/A
Computer:TUMIME1
Description:
SubSystem Message - Job 'TUMIME1-IME-TUMIME2-2' (0x73197FC085876B4BB39379788ECBA652), step 2 - Cannot TRUNCATE TABLE 'TwAccType' because it is being referenced by object 'TwAccTypeUserNotNull'.
Thanks Paul-
I will get back to you.
"Paul Ibison" wrote:

> Truncate Table can't be done if the table has FKs
> depending on it. If you look on the article properties,
> snapshot tab there is a naming conflicts section. Is yours
> set to 'Delete all data in existing table?'. If so then
> this is the cause of your error. You could drop the
> constraint in a pre-script and add it back if nesessary in
> a postscript. These options are available on the
> Publication Properties, Snapshot Tab.
> HTH,
> Paul Ibison
>