0

Long post

Hello, I keep having a problem and I can't find a solution on the internet even though some people seem to be able to fix this I can't. This happens only on my laptop when I transfer a project from one pc to another.

Now before you edit this post or you put in as it is a duplicate, or something, as most people enjoy here on stack, here is what I tried:

Nbr 1

Nbr 2

Even though this is in vb, Nbr 3

Nbr 4

Nbr 5

Nbr 6

I also tried: Reinstall visual studio, modify the connection between database and program with "replicate" and other stuff.

None worked

What I am working with:

Microsoft SQL Server

13.00.4001

Visual Studio 2017

My code:

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

        }

    }

}

If I change to user instance = true then I get:

System.Data.SqlClient.SqlException: 'The user instance login flag is not allowed when connecting to a user instance of SQL Server. The connection will be closed.'

Again, I won't list them otherwise will go on forever, but I tried all things that could possible find out there, if you want links I ll put in the comments.

No there is not another database with the same name I've triple checked. This happens with everything in VS2017 (whether is web dev, or anything else)

Nothing worked.

I don't know what to do

jjDoe
  • 1
  • 2
  • Wow, 12 days no answer, lol, not to criticize but you really see the stackoverflow community shine when they absolutely have no reason to edit or give you unreasonable bad feedback lol – jjDoe Aug 14 '17 at 19:12
  • Consider [not using `AttachDBFileName`](https://stackoverflow.com/questions/11178720). Schlepping around .MDF files is intrinsically inferior to using a database project that deploys to a LocalDB instance. For starters, database projects can be put under version control along with your project. – Jeroen Mostert Aug 14 '17 at 22:01

0 Answers0