[英]Finding Database address and connecting to it through code
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. 我刚刚使用Microsoft SQL Server Management Studio创建了一个新的SQL数据库,并试图通过一些C#代码连接到该数据库。 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 在这里查看连接字符串示例http://connectionstrings.com/sql-server-2012
Looks like it can be something like: 看起来可能是这样的:
Server=.\SQLExpress;Database=Darkride;Trusted_Connection=True;
Add "Data Source=127.0.0.1; Database=SQLExpress\\\\Darkride;Initial Catalog=YourDataBase;User Id=user;Password=pass"
添加
"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. 您可以使用
SqlConnectionStringBuilder
类来构建连接字符串。
A good site for refenrence is http://www.connectionstrings.com/ 一个不错的防御网站是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 Connectionstring.com将帮助您: SQL Server 2008的连接字符串
Best Regards 最好的祝福
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.