长篇
您好,我一直有问题而且我无法在互联网上找到解决方案,即使有些人似乎能够解决这个问题我无法解决。当我将项目从一台PC转移到另一台PC时,这只发生在我的笔记本电脑上。
现在,在你编辑这篇文章之前,或者因为大多数人喜欢这里的重复或其他东西而放入,这就是我尝试的内容:
Even though this is in vb, Nbr 3
我也尝试过:重新安装visual studio,修改数据库和程序之间的连接,用#34;复制"和其他东西。
没有工作
我正在与之合作:
Microsoft SQL Server
13.00.4001
Visual Studio 2017
我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data.SqlClient;
using System.Data;
public class DatabaseProcess{
public enum DbCommand{
ADDUSR,
REMOVEUSR,
ADDCOURSE,
REMOVECOURSE,
RETRIVEUSRINFO,
EVALUATIONCHECK,
EVALUATIONUNCHECK,
}
public DatabaseProcess(){
}
public void Connect(DbCommand dbCommand){
//string connectionString = @"connectionString=""Data Source = (localdb)\v11.0; Initial Catalog = C:\Users\My user\Documents\Visual Studio 2017\WebSites\RateMyTaWebsiteDatabase\Database.mdf; Integrated Security = True; Connect Timeout = 15; Encrypt = False; TrustServerCertificate = False";
string connectionString =
@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=""C:
\Users\My user\Documents\Visual Studio 2017\WebSites\RateMyTaWebsiteDatabase\Database.mdf"";Integrated Security=True;Connect Timeout=30";
using (SqlConnection connection = new SqlConnection(connectionString)){
RetriveUsrInfo(connection);
switch (dbCommand){
case DbCommand.ADDUSR:
break;
case DbCommand.REMOVEUSR:
break;
case DbCommand.ADDCOURSE:
Console.WriteLine("You are in add course");
break;
case DbCommand.REMOVECOURSE:
break;
case DbCommand.RETRIVEUSRINFO:
break;
case DbCommand.EVALUATIONCHECK:
break;
case DbCommand.EVALUATIONUNCHECK:
break;
}
}
}
private void RetriveUsrInfo(SqlConnection connection){
string studentTemp = ""; //Test Variable
string query =
"select a.Uid User from User a " + "INNER JOIN CoursesIntermediary Uid b ON a.Uid = b.CourseId where a.Uid = @Uid";
connection.Open(); //**Does not get past this!**
using (SqlCommand comm = new SqlCommand(query, connection)){
using (SqlDataAdapter adapter = new SqlDataAdapter(comm)){
comm.Parameters.AddWithValue("@Uid", studentTemp);
//Test variables
DataTable innerCourseTbl = new DataTable();
adapter.Fill(innerCourseTbl);
List<string[]> arrayList = new List<string[]>();
for (int i = 0; i < innerCourseTbl.Rows.Count; i++){
var arrTest = innerCourseTbl.Rows[i].ItemArray.ToString();
Console.WriteLine(arrTest.ToString());
}
foreach (var v in arrayList){
foreach (string a in v){
Console.WriteLine(a);
}
}
}
connection.Close();
}
}
}
如果我改为user instance = true,那么我得到:
System.Data.SqlClient.SqlException:&#39;连接到SQL Server的用户实例时,不允许用户实例登录标志。连接将被关闭。&#39;
再次,我不会列出它们,否则将永远继续,但我尝试了所有可能找到的东西,如果你想要我将在评论中添加的链接。
没有其他数据库具有相同的名称,我已经三次检查。 VS2017中的所有内容都会发生(无论是web dev还是其他任何内容)
没有任何效果。
我不知道该怎么做