sql - Asp.net Unable to Connect to MSSQL -



sql - Asp.net Unable to Connect to MSSQL -

when seek launch web project in asp.net mssql, seems cannot connect database. error message is:

a network related or instance specific error occurred while establishing connection sql server...

but when seek run previous projects, works. however, when select programme -> microsoft sql server 2008 -> configuration tools -> sql server configuration manager -> sql server services. instead of listing services, shows me error remote procedure phone call failed.

i wonder how prepare happens 1 of project. in advance.

my web.config codes:

edit:

<?xml version="1.0" encoding="utf-8"?> <!-- more info on how configure asp.net application, please visit http://go.microsoft.com/fwlink/?linkid=169433 --> <configuration> <configsections> <sectiongroup name="applicationsettings" type="system.configuration.applicationsettingsgroup, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"> <section name="geospatialchallenge2014.properties.settings" type="system.configuration.clientsettingssection, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> </sectiongroup> </configsections> <system.web> <webservices> <protocols> <add name="httpsoap" /> <add name="httpget" /> <add name="httppost" /> </protocols> </webservices> <compilation debug="true" targetframework="4.0"> </compilation> <pages controlrenderingcompatibilityversion="3.5" clientidmode="autoid" /> </system.web> <connectionstrings> <add name="geospatialchallengeconnectionstring" connectionstring="data source=(local);initial catalog=safety_at_sg_database.mdf;" providername="system.data.sqlclient" /> </connectionstrings> <applicationsettings> <geospatialchallenge2014.properties.settings> <setting name="geospatialchallenge2014" serializeas="string"> <value>http://localhost/sgdataservice.asmx</value> </setting> </geospatialchallenge2014.properties.settings> </applicationsettings> <system.webserver> <directorybrowse enabled="true" /> </system.webserver> </configuration>

and connection string:

using system; using system.collections.generic; using system.linq; using system.runtime.serialization; using system.text; using system.web; using system.web.services; using system.data; using system.data.sqlclient; using system.configuration; using system.xml; namespace geospatial_challenge_2014 { /// <summary> /// summary description sgdataservice /// </summary> [webservice(namespace = "http://tempuri.org/")] [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)] [system.componentmodel.toolboxitem(false)] // allow web service called script, using asp.net ajax, uncomment next line. // [system.web.script.services.scriptservice] public class sgdataservice : system.web.services.webservice { [webmethod] public dataset gettrafficbydatetime(string startdatetime, string enddatetime) { //system.data.sqlclient.sqlconnection myconn = new system.data.sqlclient.sqlconnection(); //myconn.connectionstring = @"data source=(local);initial catalog=safety_at_sg_database.mdf;integrated security=true"; sqlconnection myconn = new sqlconnection(configurationmanager.connectionstrings["geospatialchallengeconnectionstring"].connectionstring); sqldataadapter myadapter = new sqldataadapter("select * dbo.traffic convert(datetime,([date]+' '+[time])) >= @startdatetime , convert(datetime,([date]+' '+[time])) <= @enddatetime;", myconn); myadapter.selectcommand.parameters.addwithvalue("@startdatetime", startdatetime); myadapter.selectcommand.parameters.addwithvalue("@enddatetime", enddatetime); dataset ds = new dataset(); myconn.open(); myadapter.fill(ds, "traffic"); myconn.close(); homecoming ds; } } }

dude define connection string within web.config , try.like,

<connectionstrings> <add name="dbconnection" connectionstring="data source=yourservername;initial catalog=dbname;user id=sa;password=yourpassword" providername="system.data.sqlclient" /> </connectionstrings>

and within method phone call connection string

sqlconnection objconnection = new sqlconnection();//sql connection object objconnection.connectionstring = configurationmanager.connectionstrings ["dbconnection"].connectionstring; //conn string name in config file sqlcommand cmd = new sqlcommand("yourstoredprocedure", objconnection);

asp.net sql sql-server database-connection

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -