Showing posts with label eventargs. Show all posts
Showing posts with label eventargs. Show all posts

Saturday, March 24, 2012

trouble with DataReader

Hi group,

I'm trying to use a DataReader but I get an error.

This is my code:

private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection oCon = new SqlConnection("server=server;uid=id;" +
"pwd=pwd;database=database");
SqlCommand oCmd = new SqlCommand("SELECT nieuwsid, datum, titel FROM news
WHERE datum <= { fn CURDATE() })ORDER BY datum DESC",oCon);
oCon.Open();
oCmd.Connection=oCon;
SqlDataReader dr = oCmd.ExecuteReader();
oCmd.Dispose ();
oCon.Close();
oCon.Dispose();
}

I have an error at runtime on the line SqlDataReader dr =
oCmd.ExecuteReader();
The error is: Incorrect syntax near ')'.

With I simply delete the line with the error then I don't get an error, so I
think the error is in the line SqlDataReader dr = oCmd.ExecuteReader();

Can someone say what I do wrong ?

grz

Bernie V

--
http://www.djberniev.beI think you query syntax is off. Try running it in query analyzer and fix
it.

"Bernie V" <bernd.vantyghem@.pandoradotbe> wrote in message
news:uXVuK8K8DHA.2924@.tk2msftngp13.phx.gbl...
> Hi group,
> I'm trying to use a DataReader but I get an error.
> This is my code:
> private void Page_Load(object sender, System.EventArgs e)
> {
> SqlConnection oCon = new SqlConnection("server=server;uid=id;" +
> "pwd=pwd;database=database");
> SqlCommand oCmd = new SqlCommand("SELECT nieuwsid, datum, titel FROM news
> WHERE datum <= { fn CURDATE() })ORDER BY datum DESC",oCon);
> oCon.Open();
> oCmd.Connection=oCon;
> SqlDataReader dr = oCmd.ExecuteReader();
> oCmd.Dispose ();
> oCon.Close();
> oCon.Dispose();
> }
> I have an error at runtime on the line SqlDataReader dr =
> oCmd.ExecuteReader();
> The error is: Incorrect syntax near ')'.
> With I simply delete the line with the error then I don't get an error, so
I
> think the error is in the line SqlDataReader dr = oCmd.ExecuteReader();
> Can someone say what I do wrong ?
> grz
> Bernie V
>
> --
> http://www.djberniev.be
"Marina" <someone@.nospam.com> schreef in bericht
news:umi3Y$K8DHA.2064@.TK2MSFTNGP11.phx.gbl...
> I think you query syntax is off. Try running it in query analyzer and fix
> it.

Hi Marina,

This was also my first opinion. But I changed the query to a simple select
query and I had the same problem.
The query like I use works in the query analyser.

grz

Bernie V

--
http://www.djberniev.be
The error message indicates a syntax problem with the query. I would suggest
either putting a breakpoint in, or recording the generated query somewhere
so that you can copy the generated query string and run it in Query Analyzer
to find out the problem with it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Bernie V" <bernd.vantyghem@.pandoradotbe> wrote in message
news:#YfjfNL8DHA.1504@.TK2MSFTNGP12.phx.gbl...
> "Marina" <someone@.nospam.com> schreef in bericht
> news:umi3Y$K8DHA.2064@.TK2MSFTNGP11.phx.gbl...
> > I think you query syntax is off. Try running it in query analyzer and
fix
> > it.
> Hi Marina,
> This was also my first opinion. But I changed the query to a simple select
> query and I had the same problem.
> The query like I use works in the query analyser.
> grz
> Bernie V
> --
> http://www.djberniev.be
"Marina" <someone@.nospam.com> schreef in bericht
news:umi3Y$K8DHA.2064@.TK2MSFTNGP11.phx.gbl...
> I think you query syntax is off. Try running it in query analyzer and fix
> it.

Marina,

I double cheked and you 're right !
There where to many ')' .

Thx !

grz

Bernie V
Looks like you dont have a corresponding '('

Bernie V wrote:

> Hi group,
> I'm trying to use a DataReader but I get an error.
> This is my code:
> private void Page_Load(object sender, System.EventArgs e)
> {
> SqlConnection oCon = new SqlConnection("server=server;uid=id;" +
> "pwd=pwd;database=database");
> SqlCommand oCmd = new SqlCommand("SELECT nieuwsid, datum, titel FROM news
> WHERE datum <= { fn CURDATE() })ORDER BY datum DESC",oCon);
> oCon.Open();
> oCmd.Connection=oCon;
> SqlDataReader dr = oCmd.ExecuteReader();
> oCmd.Dispose ();
> oCon.Close();
> oCon.Dispose();
> }
> I have an error at runtime on the line SqlDataReader dr =
> oCmd.ExecuteReader();
> The error is: Incorrect syntax near ')'.
> With I simply delete the line with the error then I don't get an error, so I
> think the error is in the line SqlDataReader dr = oCmd.ExecuteReader();
> Can someone say what I do wrong ?
> grz
> Bernie V

--
Regards,
Dilip Krishnan
dilipkrish at msn. com

Thursday, March 22, 2012

Trouble with emailing

I use the following code to email from a form :

Sub sendEmail(Src As Object, E As EventArgs)
Dim msg as New MailMessage()
msg.To = "paul@dotnet.itags.org.mydomain.com"
msg.From = "fred@dotnet.itags.org.mydomain.com"
msg.Subject = "TESTING"
msg.BodyFormat = MailFormat.Html
msg.Body = "TESTING BODY"
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(msg)
msg = Nothing

end sub

But I keep getting the error message :

"The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for paul@dotnet.itags.org.mydomain.com"

Can anyone tell me what Im doing wrong ?

P.S. I do have the appropriate Include at the top of my page:)

You are getting this error because in smtp server your relay list is empty.

Try this :

1. In IIS right-click on the Default SMTP Virtual Server and select Properties.
2. In the Properties dialog box, selec the Access tab.
3. Click on the Relay button.
4. In the Relay Restrictions dialog box, select the Allow except the list below radio button.