c# - Error populating dropdownlist from SQL Database -
so have add data connection vs project , i'm trying populate drop down menu created data tables coming database; however, when run code says, "login failed use 'username', on line:
cmd.connection.open();
this c# code:
using system.web; using system.web.security; using system.web.ui; using system.web.ui.webcontrols; using system.web.ui.webcontrols.webparts; using system.web.ui.htmlcontrols; using system.data.sqlclient; namespace test1234 { public partial class home : system.web.ui.page { protected void page_load(object sender, eventargs e) { populateddlist1(); //populateddlist2(); //populateddlist2_1(); } public void populateddlist1() { sqlcommand cmd = new sqlcommand("select * [history]", new sqlconnection(configurationmanager.appsettings["connection"])); cmd.connection.open(); sqldatareader ddlvalues; ddlvalues = cmd.executereader(); dropdownlist1.datasource = ddlvalues; dropdownlist1.datavaluefield = "serial"; dropdownlist1.datatextfield = "serial"; dropdownlist1.databind(); cmd.connection.close(); cmd.connection.dispose(); }//end populate 1 } }
this web.config code:
<?xml version="1.0"?> <!-- more information on how configure asp.net application, please visit http://go.microsoft.com/fwlink/?linkid=169433 --> <configuration> <connectionstrings> <add name="actionetitinventoryconnectionstring" connectionstring="data source=10.10.101.188;initial catalog=actionetitinventory;user id=rails.sa;password=actionet1234" providername="system.data.sqlclient" /> </connectionstrings> <system.web> <compilation debug="true" targetframework="4.5" /> <httpruntime targetframework="4.5" /> </system.web> <appsettings> <add key="connection" value="data source=10.10.101.188;initial catalog=actionetitinventory;user id=rails.sa;password=***********;integrated security=true"/> </appsettings> </configuration>
<appsettings> <add key="connection" value="data source=10.10.101.188;initial catalog=actionetitinventory;user id=rails.sa;password=***********;integrated security=true"/> </appsettings>
your connection string contains both login & password integrated security=true
if trying log on named login/password, either set integrated security=false
or leave out altogether
Comments
Post a Comment