无法生成SQL Server的用户实例 [英] Failed to generate a user instance of SQL Server

查看:152
本文介绍了无法生成SQL Server的用户实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里我试图输入数据从ASP本地项目:文本框到数据库

在构建我得到以下...

无法生成SQL Server的用户实例。只有一个综合的连接可以生成用户实例。该连接将被关闭。

我有点困惑在这里,我已经检查了数据库,并将其与凭据我正在尝试连接活跃。

下面是code背后
C#

 命名空间OSQARv0._1
{
    公共部分类new_questionnaire:System.Web.UI.Page
    {
        SqlDataAdapter的大=新的SqlDataAdapter();
        SqlConnection的sqlcon =新的SqlConnection(@用户ID = * myuserid *;+密码= * *输入mypassword;+数据源= mssql.dev-works.co.uk;用户实例=真;+=数据库devworks_osqar+Trusted_Connection = TRUE;);        保护无效的Page_Load(对象发件人,EventArgs的发送)
        {        }
        保护无效Create_Click(对象发件人,EventArgs的发送)
        {
            DataBinder的DS =新的DataBinder();
            sqlcon.Open();
            SQLCMD的SqlCommand =新的SqlCommand(INSERT INTO问卷(QuestionnaireName)VALUES('+ qnrName.Text +'));
            sqlcmd.Parameters.AddWithValue(@名,qnrName.Text);            sqlcmd.ExecuteNonQuery();            sqlcon.Close();
        }
    }
}

任何帮助将是非常美联社preciated。

后面

编辑code(阅读以下commment)
C#

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用System.Data这;
使用System.Data.Sql;
使用System.Data.SqlClient的;命名空间OSQARv0._1
{
    公共部分类new_questionnaire:System.Web.UI.Page
    {
        保护无效的Page_Load(对象发件人,EventArgs的发送)
        {        }
        私人字符串myConnectionString;
        私人的SqlConnection的myconn;
        公共new​​_questionnaire()
        {
            的myconn =新的SqlConnection();
            myConnectionString + =数据源= mssql.database.co.uk;初始目录= devworks_osqar;用户ID =名为myusername;密码=输入mypassword;
        }        保护无效Create_Click(对象发件人,EventArgs的发送)
        {
            // DataBinder的DS =新的DataBinder();
            SQLCMD的SqlCommand =新的SqlCommand(INSERT INTO问卷(QuestionnaireName)VALUES('+ qnrName.Text +'));
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Parameters.AddWithValue(@名,qnrName.Text);
            插入(SQLCMD);        }
        私人无效插入(的SqlCommand myCommand)
        {
            myConn.Open();
            myCommand.ExecuteNonQuery();
            myConn.Close();
        }
    }
}


解决方案

<一个href=\"http://aspdotnetfaq.com/Faq/fix-error-Failed-to-generate-a-user-instance-of-SQL-Server-due-to-a-failure-in-starting-the-process-for-the-user-instance.aspx\"相对=nofollow>修正错误无法生成SQL Server的用户实例由于启动进程的用户实例失败。

从链接粘贴在基准情况下,下面的网站修改的内容在将来被删除:

第1步

在SQL Server安装启用用户实例
首先我们要确保我们已经启用了用户实例的SQL Server安装。

转到在SQL Server Management Studio来查询窗口并输入:

启用用户实例

  EXEC sp_configure的,1。

重新配置

运行此查询,然后重新启动SQL Server。

第2步

删除旧文件
现在,我们需要删除的旧用户实例。
去你的C盘,找到并彻底删除该路径(和里面的所有文件):

C:\\ Documents和Settings \\ YOUR_USERNAME \\本地设置\\应用数据\\微软\\ Microsoft SQL Server数据\\ SQLEX $ P $干燥综合征

(不要忘记你的当前用户名来替换路径中的粗体字(如果你不知道只要去C:\\ Documents和Settings \\路径看着办吧)

删除这个目录,你可以去到Visual Studio中,创建ASP.NET网站,点击你的App_Data文件夹,然后选择添加新项,然后选择SQL Server数据库,它应该工作后!

I have a local project where I am trying to input data from an ASP:textbox to a database.

On building I get the following...

"Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed."

I'm a little puzzled here, I have checked the database and it is active with the credentials i am trying to connect with.

Here is the code behind C#

    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();
        }
    }
}

Any help would be much appreciated.

Edited code behind (read commment below) C#

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();
        }
    }
}

解决方案

Fix error "Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance."

Content from link pasted and altered below in case reference site is removed in the future:

Step 1.

Enabling User Instances on your SQL Server installation First we are gonna make sure we have enabled User Instances for SQL Server installation.

Go to Query Window in SQL Server Management Studio and type this:

exec sp_configure 'user instances enabled', 1.
Go
Reconfigure

Run this query and then restart the SQL Server.

Step 2.

Deleting old files Now we need to delete any old User Instances. Go to your C drive and find and completely DELETE this path (and all files inside):

C:\Documents and Settings\ YOUR_USERNAME \Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS

(Dont forget to replace the bold text in the path with your current username (if you are not sure just go to C:\Documents and Settings\ path to figure it out).

After deleting this dir you can go to Visual Studio, create ASP.NET WebSite and click on your App_Data folder and choose Add New Item and then choose SQL Server Database and it should work!!!

这篇关于无法生成SQL Server的用户实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆