steffengy / tiberius

TDS 7.4 (mssql / Microsoft SQL Server) async driver for rust. Fork at: https://github.com/prisma/tiberius
Apache License 2.0
151 stars 2 forks source link

Invalid object name \'dbo.Test\' and missing Initial Catalog #76

Closed johnfercher closed 5 years ago

johnfercher commented 5 years ago

I'm trying to run a select query in my database on Azure. Executing in SQL Server Management Studio it works, but using Tiberius I receive the error Invalid object name \'dbo.Test\'.

Another issue that I noticed is about the Initial Catalog in connection string, I tried to add this flag in so many ways, but without success. Without this flag is not possible to connect in more than one database in the same server.

extern crate futures;
extern crate futures_state_stream;
extern crate tokio;
extern crate tiberius;
use futures::Future;
use futures_state_stream::StateStream;
use tokio::executor::current_thread;
use tiberius::SqlConnection;

fn main() {
    let conn_str = "Server=tcp:test-server.database.windows.net,1433;trustServerCertificate=False;username=username@test-server;password=password;".to_owned();

    let future = SqlConnection::connect(conn_str.as_str()).and_then(|conn| {
        conn.simple_query("SELECT TOP (1000) * FROM [dbo].[Test]")
            .for_each(|row| {
            println!("{:?}", row);
            Ok(())
        })
    });

    current_thread::block_on_all(future).unwrap();
}
steffengy commented 5 years ago

Have you tried passing database=yourDB in the connection string with yourDb replaced by the name of your database containing the Test table?

johnfercher commented 5 years ago

I will test this. Where can I find these keys to pass in the connection string?

steffengy commented 5 years ago

Well the idea is to support (some) of the keys specified here. Database is an (in my oppinion) more commonly used alias for initial catalog.

The supported keys can be found in the code only at this time.

johnfercher commented 5 years ago

It's working now :D