Note that there are some explanatory texts on larger screens.

plurals
  1. POFailed to generate a user instance of SQL Server
    primarykey
    data
    text
    <p>I have a local project where I am trying to input data from an ASP:textbox to a database.</p> <p>On building I get the following...</p> <p>"<strong>Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed.</strong>"</p> <p>I'm a little puzzled here, I have checked the database and it is active with the credentials i am trying to connect with.</p> <p>Here is the code behind C#</p> <pre><code> namespace OSQARv0._1 { public partial class new_questionnaire : System.Web.UI.Page { SqlDataAdapter da = new SqlDataAdapter(); SqlConnection sqlcon = new SqlConnection(@"user id=*myuserid*;"+"password=*mypassword*;"+"Data Source=mssql.dev-works.co.uk;User Instance=True;"+"Database=devworks_osqar"+"Trusted_Connection=true;"); protected void Page_Load(object sender, EventArgs e) { } protected void Create_Click(object sender, EventArgs e) { DataBinder ds = new DataBinder(); sqlcon.Open(); SqlCommand sqlcmd = new SqlCommand("INSERT INTO QUESTIONNAIRES (QuestionnaireName) VALUES ('"+qnrName.Text+"')"); sqlcmd.Parameters.AddWithValue("@Name", qnrName.Text); sqlcmd.ExecuteNonQuery(); sqlcon.Close(); } } } </code></pre> <p>Any help would be much appreciated.</p> <p>Edited code behind (read commment below) C#</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.Sql; using System.Data.SqlClient; namespace OSQARv0._1 { public partial class new_questionnaire : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } private string myConnectionString; private SqlConnection myConn; public new_questionnaire() { myConn = new SqlConnection(); myConnectionString += "Data Source=mssql.database.co.uk; Initial Catalog=devworks_osqar;User ID=myusername;Password=mypassword"; } protected void Create_Click(object sender, EventArgs e) { //DataBinder ds = new DataBinder(); SqlCommand sqlcmd = new SqlCommand("INSERT INTO QUESTIONNAIRES (QuestionnaireName) VALUES ('"+qnrName.Text+"')"); sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.Parameters.AddWithValue("@Name", qnrName.Text); insert(sqlcmd); } private void insert(SqlCommand myCommand) { myConn.Open(); myCommand.ExecuteNonQuery(); myConn.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.
 

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