sql连接字符串调试一步一步? [英] sql connectionstring debug step by step?

查看:172
本文介绍了sql连接字符串调试一步一步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你希望这是我最后一篇关于sql connectionsstrings ....的帖子。

Hello I hope this is my last post concerning sql connectionsstrings....

我有一个win32console应用程序写在VS2010Express,我尝试连接我的SQL服务器。
我想我做的一切正确,唯一的问题是连接字符串。有人可以确认在代码中没有其他大错误吗?

I have a win32console app written in VS2010Express and I try to connect my SQL server. I think i did everything right and that the "only" problem is the connection string. Could anyone please confirm that there is no other big mistake in the code?

关于连接字符串,我已经尝试并尝试....
一个网站建议你可以通过在桌面上创建一个connect.udl文件来获得一个有效的字符串,doublklick它和工作你的方式通过对话框。当在texteditor中再次打开它时,找到正确的连接字符串。
在我的例子中是:

Concerning the connecting string, I have tried and tried.... One site suggested that you could get a valid string by creating a connect.udl file on the desktop, doublklick it and work your way through the dialog. When opening it again in a texteditor the right connection string is found. In my case that would be:


Provider = SQLOLEDB.1; Persist Security Info = False; User ID = Test;初始目录= Stackhoover;数据源= PETERPAN \SQLEXPRESS

Provider=SQLOLEDB.1;Persist Security Info=False;User ID=Test;Initial Catalog=Stackhoover;Data Source=PETERPAN\SQLEXPRESS

字符串?看看什么部分是错误的,例如错误的pwd或服务器未找到?
防火墙现在关闭,所以这不是问题。
_hr返回E_Fail
调试器进入msado15.tli line1271

Did not work either.... Is there a way to "debug" the string? To see what part is wrong eg "wrong pwd" or "server not found"? The firewall is off right now, so that's not the problem. _hr returns "E_Fail" The debugger steps into msado15.tli line1271

感谢您的帮助!
快乐编码!

Thank you out there for any help! Happy coding!

#include "stdafx.h"
void HandleError(HRESULT)
{
MessageBox( NULL, L"ERROR", L"XX!",MB_ICONEXCLAMATION |MB_RETRYCANCEL);
}

int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr;                                     //http://en.wikipedia.org/wiki/HRESULT  

//creating a connection object
USEADO::_ConnectionPtr connection;
//create a recordset object
USEADO::_RecordsetPtr recordset;

 //      Initialize COM  
    if(FAILED(hr = CoInitialize(NULL)))
    {
        HandleError(hr); 
        return hr;
    }   

if(FAILED(hr = connection.CreateInstance(__uuidof(USEADO::Connection))))
    {
        HandleError(hr); 
        return hr;
    }

if(FAILED(hr = recordset.CreateInstance(__uuidof(USEADO::Recordset))))
    {
        HandleError(hr); 
        return hr;
    }

    connection->CursorLocation = USEADO::adUseServer; //http://dev.mysql.com/tech-resources/articles/vb-cursors-and-locks.html
                                       //adUseClient;


    //Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
    connection->Open(L"Data Source=PETERPAN\SQLEXPRESS;Initial Catalog=Stackhoover; User Id=Test; Password = Test", L"", L"", USEADO::adConnectUnspecified);
    //connection->Open(L"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=Test;Initial Catalog=Stackhoover;Data Source=PETERPAN\SQLEXPRESS", L"Test", L"Test", USEADO::adConnectUnspecified);
    //DRIVER=SQL Native Client;SERVER=.\SQLExpress;Trusted_Connection=Yes;Initial Catalog=ADOTest;
    //connection->Open(L"DRIVER=SQL Native Client;SERVER=PETERPAN\SQLEXPRESS;Trusted_Connection=Yes;Initial Catalog=Stackhoover;", L"", L"", USEADO::adConnectUnspecified);

return 0;
}

我的stdafx.h

My stdafx.h

 #pragma once
#import "C:\Program\Delade filer\System\ado\msado15.dll"    rename_namespace("USEADO"),rename("EOF","EndOfFile")
// Define ADO Namespace as global
using namespace USEADO;

#include "targetver.h"
#include <stdio.h>
#include <tchar.h>


推荐答案

您需要避开反斜杠,因此:

You need to escape backslashes, so:

connection->Open(L"Data Source=PETERPAN\SQLEXPRESS;Initial Catalog=Stackhoover; User Id=Test; Password = Test", L"", L"", USEADO::adConnectUnspecified);

应为:

connection->Open(L"Data Source=PETERPAN\\SQLEXPRESS;Initial Catalog=Stackhoover; User Id=Test; Password = Test", L"", L"", USEADO::adConnectUnspecified);

这篇关于sql连接字符串调试一步一步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆