Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Password in oledb connection string doesnt work (C#)


Message #1 by "p cymbala" <pcymbala@m...> on Thu, 19 Sep 2002 00:04:29
Can anyone tell me what's wrong with strConnection in the following 
example?

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>
<script Language="c#" runat="server">
	void Page_Load(object sender, System.EventArgs e) {
		
	
		// This doesn't work, except when I remove the password 
from the database and the connection string:

String strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; data source=" + 
Server.MapPath("db\\test.mdb")+ ";password=MyPassword";
		
		con_string.Text = strConnection + "<br/>";
		OleDbConnection conn = new OleDbConnection(strConnection);
		try {
			conn.Open();
			con_open.Text="Opened<br/>";
			conn.Close();
			con_close.Text="closed<br/>";
		}
		catch (Exception ex) {
			con_open.Text="failed<br/>";
		}
	}
</script>
<html>
<body>
<asp:label id="con_open" runat="server"/><br />
<asp:label id="con_close" runat="server"/><br />
<asp:label id="con_string" runat="server"/><br />
</body>
</html>

  Return to Index