Note that there are some explanatory texts on larger screens.

plurals
  1. POObject reference not set to an instance of an object, on SqlConnection.Open(), asp.net
    primarykey
    data
    text
    <p>just learning asp.net with c# and my code is throwing this exception when im trying to open a connection to my database:</p> <pre><code>string connectionString ="DataSource=localhost,3306;Database=somedatabase;Uid=username;Pwd=password;"; using(SqlConnection con = new SqlConnection(connectionString)) { con.Open(); // Exception Thrown Here } </code></pre> <p>Seems relatively simple, so ive really no clue why this is happening.</p> <p>one other thing;</p> <p>all this code is inside tags on the webpage (not really sure if that makes any difference, quite new to asp.net)</p> <p>Cheers!</p> <p>edit-</p> <p>Hey, here is the rest of it. Im going to investigate habib's solution.</p> <p>I am missing some assemblies (mysql), but ill get back when ive tried it out.</p> <pre><code>&lt;%@ Language=C# %&gt; &lt;%@ Import Namespace="System.Data" %&gt; &lt;%@ Import Namespace="System.Data.SqlClient" %&gt; &lt;%@ Import Namespace="MySql" %&gt; &lt;HTML&gt; &lt;script runat="server" language="C#"&gt; void MyButton_OnClick(Object sender, EventArgs e) { } void Page_Load(Object sender, EventArgs e) { // GET THE USERNAME AND PASSWORD FROM THE CLIENT NameValueCollection nvc = Request.Form; string username = nvc["username"]; string password = nvc["password"]; Login(username, password); } void Login(string username, string password) { string connectionString = "Data Source=localhost,3306;Database=something;Uid=somename;Pwd=somepass;"; using(MySqlConnection con = new MySqlConnection(connectionString)) { con.Open(); /* if (con.State != ConnectionState.Open) return; try { SqlDataReader reader = null; SqlCommand command = new SqlCommand("SELECT * FROM accounts WHERE username=@username AND password=@password", con); reader = command.ExecuteReader(); Response.Write(reader[0]); } catch (Exception e) { Response.Write(e.ToString()); } con.Close();*/ } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload