作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我安装了带有 Visual Studio 2010 的 SQL Server 2008,我下载了一个项目,其中包含在 Visual Studio 项目本身中创建的数据库文件,现在我想连接到该数据库。
我尝试更改连接字符串但无法连接到数据库。
谁能告诉我如何连接到数据库,我的机器上安装了 SQL Server 2008 (10.0.1600.22)
更新的连接字符串:
这是我使用的连接字符串
Data Source=SQLEXPRESS\;Initial Catalog=INVENTORY;uid=xxx;pwd=xxx
其中 xxx\xxx
分别是我的机器和我安装的 SQL Server 实例名称。
最佳答案
您使用的是 C# 吗?
试试这个:
using namespace System.Data.SqlClient;
SqlConnection con = new SqlConnection("Data source = [ip]; Initial catalog = [db name]; User id = [user name]; password = [password]");
con.Open();
在con.Open()处设置断点,如果成功并通过这一行,则表示连接成功。
之后,你可能想执行一个 SQL 命令试试这个:
SqlCommand cmd = new SqlCommand("[command]", con);
// if the command has no return value
cmd.ExecuteNonQuery();
//else you might want a Sql data reader to read the return value
SqlDataReader read = cmd.ExecuteReader();
while(read.Read())
{
//do something
}
关于c# - 从 Visual Studio 连接到 SQL Server Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15127073/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!