Thursday, July 19, 2007

How to send mail on a GoDaddy hosted website, using ASP.NET (C#)

//Right click on class library
//Add Reference option
//.NET Components
//System.Web -> then add it, now you can type using System.Web.Mail

using System.Web.Mail;

public class EmailInfo //instantiate this on the page that you have your info to email
{
private string fromemailaddress = "@.com";
private string toemailaddress = "@.com";
private string host = "relay-hosting.secureserver.net";

//These private strings are the connection information, they are private so someone couldn't
//download your DLL and do simple code to figure out the value of these

public void SendMail(string body) //I built the body in a function in the behind-code
{
MailMessage message = new MailMessage();
message.From = fromemailaddress;
message.To = toemailaddress;
message.Subject = ;
message.BodyFormat = MailFormat.Html;
message.Priority = MailPriority.Normal;
message.Body = body;
SmtpMail.SmtpServer = host;
SmtpMail.Send(message);
message = null;
}
}

EXCEPTION: add assembly="VsWebSite.Interop, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A

Open:
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\

Copy: VsWebsite.Interop.dll

Open: your website's directory
i.e. C:\MyWebSite\Bin

Paste

Open VS2005

Refresh Folder Bin

Thursday, July 12, 2007

SQL Server connection error[40] doesn't allow remote access

Today I was learning how to use SQL Databases and came upon a really stupid problem. I am trying to connect to a database on the computer im using, and this error pops up. Im not trying to connect to a remote computer, so why the hell is it giving me this error?

Heres some solutions I found while googling my way to success. Solution 1 allows a client to connect to the server computer. Solution 2 is used for the same reason. Solution 3 however solved my problem, when the error comes up using your computer as the server.


Mandatory code for testing
Using C# code under an event handling button type this:
First create a button and a label.
SqlConnection con = new SqlConnection(@"Server=localhost\SQLExpress;Initial Catalog=;Integration Security=true");
con.Open( );
label1.Text = "This connection worked";
con.Close( );

After each solution Start Debugging to test your connection. If your connection will actually work the label1 text will appear. Otherwise it will take about 10 seconds to tell you an error has occurred.

Solution 1: Enable things
1. Start->Run->Type "cliconfg.exe" -> Ok
2. Click TCP/IP -> Enabled
3. Click Named Pipes -> Enabled
4. Apply and leave
5. Debug program

Solution 2: Allow a port to be unblocked
1. Start->Run->Type "firewall.cpl"->Ok
2. Exceptions -> Add Port...
3. Add port "1433"
4. Check TCP -> Ok
5. Debug program

Solution 3: If you are getting this problem on a local host
1. Download http://www.microsoft.com/downloads/details.aspx?FamilyID=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796&DisplayLang=en
2. Its used to manage SQL databases
3. Create a database on that tool
4. Open Visual Studio 2005
5. View->Server Explorer
6. Click Connect to Database
7. Datasource = "Microsoft SQL Server (SqlClient)"
8. Server name= /SQLExpress
9. Check Windows Authentication
10. Select "Select or Enter a Database name"
11. On the list, your database you created with the posted tool will come up
12. Test Connection
13. Ok
14. Debug program
There was an error in this gadget