I've just made a new SQL Database with Microsoft SQL Server Management Studio and I'm trying to connect to it through some C# code. However, I'm having some issues doing so.
I'm trying to connect to my database with the following line:
String DBConnection = "Data Source=unknown; Database=SQLExpress\\Darkride; Language=English";
However my program can't find my database as I have no idea where my data source is. I've been trying to find it for hours now, but I'm getting nothing.
Does anyone know where I can find out my databases Data Source?
Take a look on the connection string examples here http://connectionstrings.com/sql-server-2012
Looks like it can be something like:
Server=.\SQLExpress;Database=Darkride;Trusted_Connection=True;
you are missing Initial Catalog
in the connection string:
String DBConnection ="Data Source='localhost';Integrated Security='SSPI' Initial Catalog=Darkride;";
check here for more options.
Add "Data Source=127.0.0.1; Database=SQLExpress\\\\Darkride;Initial Catalog=YourDataBase;User Id=user;Password=pass"
You can use the SqlConnectionStringBuilder
class to build your connection string.
A good site for refenrence is http://www.connectionstrings.com/
连接字符串格式为:
String DBConnection = "Data Source=27.0.0.1;;Initial Catalog=Darkride;User ID=userIDText;Password=PasswordText";
Change your code to this:
Server=.\SQLExpress;Database=Darkride;Trusted_Connection=True;
And take a look on the link below
Connectionstring.com will help : Connection strings for SQL Server 2008
Best Regards
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.