My IT dept set up an SQL db on a server for me and I am connected to it through a port. They told me I had to create my tables through an MS Access adp, which I have done. I am using VWD Express and am trying to create a login page using usernames and pw's from a db table. I am connected (at least the db Explorer tab shows I am) to the MS Access adp and can drop a GridView from my Employees table from it onto a page and get results. I keep getting the "ConnectionString property not initialized" error message pointing to my sqlConn.Open() statement and cannot figure out why. I have looked at hundreds of posts but can't seem to find anything that works. If someone could point me to some post or website that could explain connecting to a SQL db through a port or whatever you think I need to learn to get this fixed I would appreciate it.
Web config:
<configurationxmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings>
<addname="ASPNETDB"connectionString="Description=Training;DRIVER=SQL Server;SERVER=USAWVAS27;UID=usx14611;APP=Microsoft? Visual Studio? 2005;WSID=983QD21;Network=DBMSSOCN;Address=USAWVAS27,3180;Trusted_Connection=Yes"providerName="System.Data.Odbc"/>
</connectionStrings>
<system.web>
<authenticationmode="Forms" />
<authorization>
<denyusers="?" />
</authorization>
<customErrorsmode="Off" />
</system.web>
</configuration>
My login.aspx page
<%@.PageLanguage="VB"debug="true"%>
<%@.ImportNamespace="System.Data.SqlClient" %>
<%@.ImportNamespace="System.Configuration.ConfigurationManager" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scriptrunat="server">
ProtectedSub LoginUser(ByVal sAsObject,ByVal eAs EventArgs)
Dim blnAuthenticateAsBoolean = Authenticate(username.Text, password.Text)
If blnAuthenticateThen
FormsAuthentication.RedirectFromLoginPage(username.Text,False)
EndIf
EndSub
Function Authenticate(ByVal strUsernameAsString,ByVal strPasswordAsString)AsBoolean
Dim strConnectionAsString = ConfigurationManager.AppSettings("ASPNETDB")
Tried this code as well
Dim sqlConn As New SqlConnection(ConfigurationManager.AppSettings("ASPNETDB"))
Dim sqlConnAsNew SqlConnection(strConnection)
Dim sqlCmdAs SqlCommand
Dim sqlDRAs SqlDataReader
Dim userFoundAsBoolean
sqlCmd =New SqlCommand("SELECT * FROM Employees " & _
"WHERE username='" & strUsername &" ' AND password='" & strPassword &"'", sqlConn)
sqlConn.Open()
sqlDR = sqlCmd.ExecuteReader()
userFound = sqlDR.Read()
sqlDR.Close()
Return userFound
EndFunction
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<p>Username:<asp:TextBoxID="username"runat="server"></asp:TextBox><br/>
<br/>
<p>Password:<asp:TextBoxID="password"runat="server"></asp:TextBox><br/>
<br/>
<asp:ButtonID="btnSubmit"runat="server"Text="Login"OnClick="LoginUser"/> </div>
</form>
</body>
</html>
Thanks
I removed my database connection and reconnected which gave me this as a new connection string:
<connectionStrings>
<addname="connString"connectionString="Data Source=USAWVAS27;Initial Catalog=MaterialsTraining;Integrated Security=False"/>
</connectionStrings>
Anybody have any ideas?
Thanks,
Toni
Looks like this:
Dim strConnectionAsString = ConfigurationManager.AppSettings("ASPNETDB")
Should be this:
Dim strConnectionAsString = ConfigurationManager.ConnectionStrings("ASPNETDB").ConnectionString
|||Finally got this figured out so thought I'd share it. Thanks to those who responded with suggestions. It didn't like "DRIVER" and "Description" in my original system generated connection string, I'm assuming because it is an SQL database (?)
<connectionStrings>
<addname="ASPNETDB"connectionString="DataSource=Training;server=USAWVAS27;wsid=983QD21;network=DBMSSOCN;address=USAWVAS27,3180;trusted_connection=Yes"/>
</connectionStrings>
Protected Sub loginBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles loginBtn.Click
Dim strConnection As String = ConfigurationManager.AppSettings("sups")
Dim conn As New SqlConnection(strConnection)
Dim cmd As SqlCommand
Dim read As SqlDataReader
conn.Open()
The web.config file is like this...
<configuration>
<appSettings/>
<connectionStrings>
<add name="sups"connectionString="server=localhost;Trusted_Connection=true;database=sups;uid=abcd; pwd=abcd;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
Where am I going wrong? Thanks a lot
|||I fixed this error with this if anyone is having problems
Dim sSQL As String
sSQL = "SELECT * FROM optionitems WHERE id=" & ID.ToString
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("cre8StoreConnectionString").ConnectionString)
Dim cmd As New SqlCommand(sSQL)
conn.Open()
cmd.Connection = conn
Dim reader As SqlDataReader = cmd.ExecuteReader
the problem I was having to genrate this error was caused because I was using the datareader without assigning a connection to the SQLcommand object.
No comments:
Post a Comment